package business.global.pk.sss;

import java.util.ArrayList;
import java.util.List;

public class SSSLogic {
int m_cbCity = 1;
int m_cbTongHuaMode = 0;
    int m_cbFrontASmall = 0;
//数值掩码
public static final int LOGIC_MASK_COLOR=			0xF0;								//花色掩码
    public static final int LOGIC_MASK_VALUE=			0x0F;								//数值掩码
    public static final int HAND_CARD_COUNT=					13;									//扑克数目
    public static final int DISPATCH_COUNT=					52;									//派发数目


    public static final int cbIndexCount = 4;
public static final int CT_INVALID=						0;								//错误类型
    public static final int CT_SINGLE=						1;								//单牌类型
    public static final int CT_ONE_DOUBLE=					2;								//只有一对
    public static final int CT_TWO_DOUBLE=					3;								//两对牌型
    public static final int CT_THREE=						4;								//三张牌型
    public static final int CT_FIVE_MIXED_FLUSH_NO_A=		5;								//普通顺子
    public static final int CT_FIVE_MIXED_FLUSH_FIRST_A=		6;								//A前顺子
    public static final int CT_FIVE_MIXED_FLUSH_BACK_A=		7;								//A后顺子
    public static final int CT_FIVE_FLUSH=					8;								//同花
    public static final int CT_FIVE_FLUSH_DOUBLE=			9;								//对子花
    public static final int CT_FIVE_FLUSH_TWO_DOUBLE=		10;								//对子花 两对
    public static final int CT_FIVE_THREE_DEOUBLE=			11;								//三条一对
    public static final int CT_FIVE_FOUR_ONE=				12;								//四带一张
    public static final int CT_FIVE_STRAIGHT_FLUSH_NO_A=		13;								//同花顺牌
    public static final int CT_FIVE_STRAIGHT_FLUSH_FIRST_A=	14;								//A前同花顺
    public static final int CT_FIVE_STRAIGHT_FLUSH_BACK_A=	15;								//A后同花顺
    public static final int CT_FIVE_SAME=					31;								//5同

//特殊类型
public static final int CT_EX_INVALID=					16;								//非特殊牌
    public static final int CT_EX_SANSHUNZI=					17;								//三顺子
    public static final int CT_EX_SANTONGHUA=				18;								//三同花
    public static final int CT_EX_LIUDUIBAN=					19;								//六对半
    public static final int CT_EX_SITAOSANTIAO=				21;								//四套三条
            /*
             */
            public static final int CT_EX_WUDUISANTIAO=				20;								//五对三条
    public static final int CT_EX_SHUANGGUAICHONGSAN=		22;								//双怪冲三
    public static final int CT_EX_COUYISE=					23;								//凑一色
    public static final int CT_EX_QUANXIAO=					24;								//全小
    public static final int CT_EX_QUANDA=					25;								//全大
    public static final int CT_EX_SANFENGTIANXIA=			26;								//三分天下
    public static final int CT_EX_SANTONGHUASHUN=			27;								//三同花顺
    public static final int CT_EX_SHIERHUANGZU=				28;								//十二皇族
    public static final int CT_EX_YITIAOLONG=				29;								//一条龙
    public static final int CT_EX_ZHIZUNQINGLONG=			30;								//至尊清龙

    public static final int CT_EX_QILAOTOU=					32;								//七老头
    public static final int CT_EX_BALAOTOU=					33;								//8老头
    public static final int CT_EX_JIULAOTOU=					34;								//9老头
    public static final int CT_EX_QUANHONG1HEI=				35;								//全红一点黑
    public static final int CT_EX_QUANHEI1HONG=				36;								//全hei一点红
    public static final int CT_EX_QUANHEI=					37;								//全黑
    public static final int CT_EX_QUANHONG=					38;								//全红
    public static final int CT_SIX_SAME=						39;								//6同
    public static final int CT_COUYISE= 						40;								//凑一色


    public int AutoThreePutCard(int bCardData[], int bPutCardData[][])
    {
        int bTempCard[][][] = new int[6][3][5]; //保存权值最大的六副牌型
        int  iTempWeights[][] = new int[6][3]; //保存权值最大的六副牌型的权值
        int bCardList[] = new int[13];      //保存手牌
        int bCard[][] = new int[3][5];        //临时存放牌
        int bSubscript[] = new int[13];     //下标用来保存每一注使用的哪些牌
        boolean blBiaoJi[] = new boolean[13];       //标记那些牌没有使用
        int iFWeights, iSWeights, iTWeights;
        int bWCard = 0;

        for (int i = 0; i < 13; i++) {
            bCardList[i] = bCardData[i];
        }
//        CopyMemory(bCardList, bCardData, sizeof(int) * 13);
        //ZeroMemory(bTempCard, sizeof(bTempCard));
        //ZeroMemory(iTempWeights, sizeof(iTempWeights));
        //ZeroMemory(bCard, sizeof(bCard));
        //ZeroMemory(blBiaoJi, sizeof(blBiaoJi));

        //进行全排列寻找最优牌型
        SortCardList(bCardList, 13, enSortCardType.enAscend);

        //第一注使用的三张牌
        for (bSubscript[0] = 0; bSubscript[0] < 13; bSubscript[0] ++)
            for (bSubscript[1] = bSubscript[0] + 1; bSubscript[1] < 13; bSubscript[1] ++)
                for (bSubscript[2] = bSubscript[1] + 1; bSubscript[2] < 13; bSubscript[2] ++)
                {
                    //从大到小将牌保存到bCard[2]数组中，将已经使用的牌进行标记
                    for (int i = 0; i < 3; i++)
                    {
                        blBiaoJi[bSubscript[i]] = true;
                        bCard[2][2 - i] = bCardList[bSubscript[i]];
                    }
                    //第二注使用的五张牌
                    for (bSubscript[3] = 0; bSubscript[3] < 13; bSubscript[3] ++)
                        if (!blBiaoJi[bSubscript[3]]) for (bSubscript[4] = bSubscript[3] + 1; bSubscript[4] < 13; bSubscript[4] ++)
                            if (!blBiaoJi[bSubscript[4]]) for (bSubscript[5] = bSubscript[4] + 1; bSubscript[5] < 13; bSubscript[5] ++)
                                if (!blBiaoJi[bSubscript[5]]) for (bSubscript[6] = bSubscript[5] + 1; bSubscript[6] < 13; bSubscript[6] ++)
                                    if (!blBiaoJi[bSubscript[6]]) for (bSubscript[7] = bSubscript[6] + 1; bSubscript[7] < 13; bSubscript[7] ++)
                                        if (!blBiaoJi[bSubscript[7]]) {
                                            do {

                                                //从大到小将牌保存到bCard[1]数组中，将已经使用的牌进行标记
                                                for (int i = 0; i < 5; i++)
                                                {
                                                    blBiaoJi[bSubscript[3 + i]] = true;
                                                    bCard[1][4 - i] = bCardList[bSubscript[3 + i]];
                                                }

                                                iFWeights = CardTypeToWeights(GetCardType(bCard[2], 3, bWCard), 1);
                                                iSWeights = CardTypeToWeights(GetCardType(bCard[1], 5, bWCard), 2);

                                                //比较第一注和第二注牌型权值的大小
                                                if (iFWeights > iSWeights)
                                                {
                                                    break;
                                                }

                                                //将剩下元素放入bCard[0]数组当中
                                                int iCount = 0;
                                                for (int i = 0; i < 13; i++)
                                                    if (!blBiaoJi[i]) {
                                                        bCard[0][iCount++] = bCardList[i];
                                                    }

                                                iTWeights = CardTypeToWeights(GetCardType(bCard[0], 5, bWCard), 3);
                                                if (iSWeights > iTWeights)
                                                {
                                                    break;
                                                }

                                                boolean bHave = false;
                                                for (int i = 0; i < 6; i++)
                                                {
                                                    //已经存在三注牌型都不小于它的组合，就放弃
                                                    if (iFWeights <= iTempWeights[i][2] && iSWeights <= iTempWeights[i][1] && iTWeights <= iTempWeights[i][0])
                                                    {
                                                        bHave = true;
                                                        break;
                                                    }
                                                }

                                                if (false == bHave)
                                                {

                                                    //不存在就保存
                                                    for (int i = 0; i < 6; i++)
                                                        if (iFWeights >= iTempWeights[i][2] && iSWeights >= iTempWeights[i][1] && iTWeights >= iTempWeights[i][0])
                                                        {
                                                            iTempWeights[i][2] = iFWeights;
                                                            iTempWeights[i][1] = iSWeights;
                                                            iTempWeights[i][0] = iTWeights;

                                                            for (int j = 0; j < 3; j++)
                                                            {
                                                                for (int k = 0; k < 5; k++) {
                                                                    bTempCard[i][j][k] = bCard[j][k];
                                                                }
//                                                                CopyMemory(bTempCard[i][j], bCard[j], sizeof(int)* 5);
                                                            }
                                                            for (int j = i + 1; j < 6; j++)
                                                            {
                                                                if (iFWeights >= iTempWeights[j][2] && iSWeights >= iTempWeights[j][1] && iTWeights >= iTempWeights[j][0])
                                                                {
                                                                    iTempWeights[j][2] = 0;
                                                                    iTempWeights[j][1] = 0;
                                                                    iTempWeights[j][0] = 0;
                                                                }
                                                            }
                                                            break;
                                                        }
                                                }
                                            } while (false);

                                            for (int i = 0; i < 5; i++)
                                            {
                                                blBiaoJi[bSubscript[3 + i]] = false;
                                            }
                                        }

                    //清除标记
                    for (int i = 0; i < 3; i++)
                    {
                        blBiaoJi[bSubscript[i]] = false;
                    }
                }
        //将权值没法比上一种牌型组合优的去掉
        for (int i = 0; i < 6; i++)
        {
            for (int j = i + 1; j < 6; j++)
            {
                if (iTempWeights[j][0] <= iTempWeights[i][0] && iTempWeights[j][1] <= iTempWeights[i][1] && iTempWeights[j][2] <= iTempWeights[i][2])
                {
                    iTempWeights[j][0] = 0;
                    iTempWeights[j][1] = 0;
                    iTempWeights[j][2] = 0;
                }
            }
        }

        //将中间出现的空隙删除
        int iCount = 0;
        for (int i = 0; i < 6; i++)
        {
            if (iTempWeights[i][0] != 0)
            {
                for (int j = 0; j < 3; j++)
                {
                    for (int k = 0; k < 5; k++) {
                        bTempCard[iCount][j][k] = bTempCard[i][j][k];
                    }
//                    CopyMemory(bTempCard[iCount][j], bTempCard[i][j], sizeof(int)* 5);
                    iTempWeights[iCount][j] = iTempWeights[i][j];
                }
                iCount++;
            }

        }

        //按权值排序
        for (int i = 0; i < 6; i++)
        {
            for (int j = i + 1; j < 6; j++)
            {
                if ((iTempWeights[j][0] + iTempWeights[j][1] + iTempWeights[j][2]) >(iTempWeights[i][0] + iTempWeights[i][1] + iTempWeights[i][2]) ||
                        ((iTempWeights[j][0] + iTempWeights[j][1] + iTempWeights[j][2]) == (iTempWeights[i][0] + iTempWeights[i][1] + iTempWeights[i][2]) &&
                                (iTempWeights[j][0] > iTempWeights[i][0] || (iTempWeights[j][0] == iTempWeights[i][0] && iTempWeights[j][1] > iTempWeights[i][1]))))
                {
                    for (int k = 0; k < 3; k++)
                    {
                        int iTemp;

                        iTemp = iTempWeights[i][k];
                        iTempWeights[i][k] = iTempWeights[j][k];
                        iTempWeights[j][k] = iTemp;

                        for (int l = 0; l < 5; l++) {
                            bCard[k][l] = bTempCard[i][k][l];
                            bTempCard[i][k][l] = bTempCard[j][k][l];
                            bTempCard[j][k][l] = bCard[k][l];
                        }
//                        CopyMemory(bCard[k], bTempCard[i][k], sizeof(int) * 5);
//                        CopyMemory(bTempCard[i][k], bTempCard[j][k], sizeof(int) * 5);
//                        CopyMemory(bTempCard[j][k], bCard[k], sizeof(int) * 5);
                    }
                }
            }
        }

        //最大3副牌
        if (iCount > 3)
        {
            iCount = 3;
        }

        int bIx = 0;
        for (int i = 0; i < iCount; i++)
        {
            boolean isExsit = false;
            for (int j = 0; j < bIx; j++)
            {
                boolean notSame = false;
                for (int k = 0; k < 5; k++) {
                    if(bPutCardData[j][k] != bTempCard[i][2][k]){
                        notSame = true;
                    }
                }
                for (int k = 0; k < 5; k++) {
                    if(bPutCardData[j][k+5] != bTempCard[i+1][0][k]){
                        notSame = true;
                    }
                }
                for (int k = 0; k < 3; k++) {
                    if(bPutCardData[j][k+10] != bTempCard[i+1][1][k]){
                        notSame = true;
                    }
                }
                if(!notSame){
                    isExsit = true;
                    break;
                }
//                if (RtlEqualMemory(bPutCardData[j], bTempCard[i][2], sizeof(int)* 13))zhaozw 可能需要修改
//                {
//                    isExsit = true;
//                    break;
//                }
//                for (int k = 0; k < 13; k++) {
//                    if(bPutCardData[j][k+5] != bTempCard[i+1][0][k]){
//                        notSame = true;
//                    }
//                }

            }

            if (isExsit) continue;
            //牌组填充
            for (int l = 0; l < 3; l++) {
                bPutCardData[bIx][l] = bTempCard[i][2][l];
            }
            for (int l = 0; l < 5; l++) {
                bPutCardData[bIx][l+3] = bTempCard[i][1][l];
                bPutCardData[bIx][l+8] = bTempCard[i][0][l];
            }
//            CopyMemory(bPutCardData[bIx], bTempCard[i][2], sizeof(int)* 3);
//            CopyMemory(bPutCardData[bIx] + 3, bTempCard[i][1], sizeof(int)* 5);
//            CopyMemory(bPutCardData[bIx] + 8, bTempCard[i][0], sizeof(int)* 5);
            bIx++;
        }

        for (int i = 0; i < bIx; i++)
        {
            int[] temp1 = new int[3];
            int[] temp2 = new int[5];
            int[] temp3 = new int[5];
            for (int j = 0; j < 3; j++) {
                temp1[j] = bPutCardData[i][j];
            }
            for (int j = 0; j < 5; j++) {
                temp2[j] = bPutCardData[i][j+3];
            }
            for (int j = 0; j < 5; j++) {
                temp3[j] = bPutCardData[i][j+8];
            }
            OptimizationCombo(temp2 , temp3, 5, 5,3,8);
            OptimizationCombo(temp1, temp3, 3, 5,0,8);
            OptimizationCombo(temp1, temp2, 3, 5,0,3);
            for (int j = 0; j < 3; j++) {
                bPutCardData[i][j] = temp1[j];
            }
            for (int j = 0; j < 5; j++) {
                bPutCardData[i][j+3] = temp2[j];
            }
            for (int j = 0; j < 5; j++) {
                bPutCardData[i][j+8] = temp3[j];
            }
        }
        return bIx;
    }

    //排列扑克
    void SortCardList(int bCardData[], int bCardCount, enSortCardType SortCardType)
    {
        if (bCardCount < 1 || bCardCount>13) return;

        //转换数值
        int bLogicVolue[] = new int[13];
        for (int i = 0; i < bCardCount; i++)	bLogicVolue[i] = GetCardLogicValue(bCardData[i]);

        if (enSortCardType.enDescend == SortCardType)
        {
            //排序操作
            boolean bSorted = true;
            int bTempData, bLast = bCardCount - 1;
            int m_bCardCount = 1;
            do
            {
                bSorted = true;
                for (int i = 0; i < bLast; i++)
                {
                    if ((bLogicVolue[i] < bLogicVolue[i + 1]) ||
                            ((bLogicVolue[i] == bLogicVolue[i + 1]) && (bCardData[i] < bCardData[i + 1])))
                    {
                        //交换位置
                        bTempData = bCardData[i];
                        bCardData[i] = bCardData[i + 1];
                        bCardData[i + 1] = bTempData;
                        bTempData = bLogicVolue[i];
                        bLogicVolue[i] = bLogicVolue[i + 1];
                        bLogicVolue[i + 1] = bTempData;
                        bSorted = false;
                    }
                }
                bLast--;
            } while (bSorted == false);
        }
        else if (enSortCardType.enAscend == SortCardType)
        {
            //排序操作
            boolean bSorted = true;
            int bTempData, bLast = bCardCount - 1;
            int m_bCardCount = 1;
            do
            {
                bSorted = true;
                for (int i = 0; i < bLast; i++)
                {
                    if ((bLogicVolue[i] > bLogicVolue[i + 1]) ||
                            ((bLogicVolue[i] == bLogicVolue[i + 1]) && (bCardData[i] > bCardData[i + 1])))
                    {
                        //交换位置
                        bTempData = bCardData[i];
                        bCardData[i] = bCardData[i + 1];
                        bCardData[i + 1] = bTempData;
                        bTempData = bLogicVolue[i];
                        bLogicVolue[i] = bLogicVolue[i + 1];
                        bLogicVolue[i + 1] = bTempData;
                        bSorted = false;
                    }
                }
                bLast--;
            } while (bSorted == false);
        }
        else if (enSortCardType.enColor == SortCardType)
        {
            //排序操作
            boolean bSorted = true;
            int bTempData, bLast = bCardCount - 1;
            int m_bCardCount = 1;
            int bColor[] = new int[13];
            for (int i = 0; i < bCardCount; i++)	bColor[i] = GetCardColor(bCardData[i]);
            do
            {
                bSorted = true;
                for (int i = 0; i < bLast; i++)
                {
                    if ((bColor[i] < bColor[i + 1]) ||
                            ((bColor[i] == bColor[i + 1]) && (GetCardLogicValue(bCardData[i]) < GetCardLogicValue(bCardData[i + 1]))))
                    {
                        //交换位置
                        bTempData = bCardData[i];
                        bCardData[i] = bCardData[i + 1];
                        bCardData[i + 1] = bTempData;
                        bTempData = bColor[i];
                        bColor[i] = bColor[i + 1];
                        bColor[i + 1] = bTempData;
                        bSorted = false;
                    }
                }
                bLast--;
            } while (bSorted == false);
        }
        //else
        //	MyMsgBox(_T("错误排列类型！"));

        return;
    }

    /****************************************************
     *函数名：OptimizationCombo
     *功能：  对已经摆好的牌序列进行优化，让摆出的牌显得更合理
     *参数：	 bInFirstList		第一组牌数据	IN/OUT
     *参数：	 bInNextList		第二组牌数据	IN/OUT
     *参数：	 bFirstCount		第一组牌张数	IN
     *参数：	 bNextCount 		第二组牌张数	IN
     *返回值：无(本函数要保证第一组牌型大小不大于第二组牌型)
     ****************************************************/
    void OptimizationCombo(int bInFirstList[], int bInNextList[], int bFirstCount, int bNextCount, int bFirstStart, int bNextStart)
    {

        if (bFirstCount <= bNextCount && (3 == bFirstCount || 5 == bFirstCount) && 5 == bNextCount)
        {

            //获取类型
            int cbMaxCard = 0;
            int bNextType = GetCardType(bInNextList, bNextCount, cbMaxCard);
            int bFirstType = GetCardType(bInFirstList, bFirstCount, cbMaxCard);
            int bFirstCard[] = new int[5], bNextCard[] = new int[5];
            int iTemp1=0, iTemp2=0;

            if (bFirstCount == bNextCount && COMRESULT.enCRLess == CompareCard(bInFirstList, bInNextList, 5, 5, true))
            {
                for (int i = 0; i < 5; i++) {
                    bFirstCard[i] = bInFirstList[i];
                }
                for (int i = 0; i < 5; i++) {
                    bNextCard[i] = bInNextList[i];
                }
                for (int i = 0; i < 5; i++) {
                    bInFirstList[i] = bNextCard[i];
                }
                for (int i = 0; i < 5; i++) {
                    bInNextList[i] = bFirstCard[i];
                }
//                CopyMemory(bFirstCard, bInFirstList, sizeof(int)* 5);
//                CopyMemory(bNextCard, bInNextList, sizeof(int)* 5);
//                CopyMemory(bInFirstList, bNextCard, sizeof(int)* 5);
//                CopyMemory(bInNextList, bFirstCard, sizeof(int)* 5);
            }


            //牌型相同不进行优化
            if (bFirstType == bNextType)
            {
                return;
            }
            switch (bNextType)
            {
                case CT_INVALID:												//错误类型
                case CT_SINGLE:													//单牌类型
                case CT_FIVE_MIXED_FLUSH_NO_A:									//普通顺子
                case CT_FIVE_MIXED_FLUSH_FIRST_A:								//A前顺子
                case CT_FIVE_MIXED_FLUSH_BACK_A:								//A后顺子
                case CT_FIVE_FLUSH:												//同花
                case CT_FIVE_STRAIGHT_FLUSH_NO_A:								//同花顺牌
                case CT_FIVE_STRAIGHT_FLUSH_FIRST_A:							//A前同花顺
                case CT_FIVE_STRAIGHT_FLUSH_BACK_A:								//A后同花顺
                {
                    //这些牌型无需优化直接返回
                    return;
                }
                case CT_ONE_DOUBLE:												//只有一对
                case CT_THREE:													//三张牌型
                case CT_FIVE_FOUR_ONE:											//四带一张
                {
                    //对原有的对子(三张、四张)进行保存不允许修改
                    for (int i = 0; i < (bNextCount - 1); i++)
                    {
                        if (GetCardLogicValue(bInNextList[i]) == GetCardLogicValue(bInNextList[i + 1]))
                        {
                            iTemp1 = GetCardLogicValue(bInNextList[i]);
                            break;
                        }
                    }

                    //对剩下的单牌进行置换，在不破坏牌型的情况下将大的单牌放在前面一注
                    for (int i = 0; i < bNextCount; i++)
                    {
                        if (GetCardLogicValue(bInNextList[i]) != iTemp1)
                        {
                            for (int j = bFirstCount - 1; j >= 0; j--)
                            {
                                if (GetCardLogicValue(bInNextList[i]) > GetCardLogicValue(bInFirstList[j]))
                                {
                                    for (int k = 0; k < bFirstCount; k++) {
                                        bFirstCard[k] = bInFirstList[k];
                                    }
                                    for (int k = 0; k < bNextCount; k++) {
                                        bNextCard[k] = bInNextList[k];
                                    }
//                                    CopyMemory(bFirstCard, bInFirstList, sizeof(int)* bFirstCount);
//                                    CopyMemory(bNextCard, bInNextList, sizeof(int)* bNextCount);
                                    bFirstCard[j] = bInNextList[i];
                                    bNextCard[i] = bInFirstList[j];
                                    SortCardList(bFirstCard, bFirstCount, enSortCardType.enDescend);
                                    SortCardList(bNextCard, bNextCount, enSortCardType.enDescend);
                                    if (bFirstType == GetCardType(bFirstCard, bFirstCount, cbMaxCard) &&
                                            bNextType == GetCardType(bNextCard, bNextCount, cbMaxCard))
                                    {
                                        for (int k = 0; k < bFirstCount; k++) {
                                            bInFirstList[k] = bFirstCard[k];
                                        }
                                        for (int k = 0; k < bNextCount; k++) {
                                            bInNextList[k] = bNextCard[k];
                                        }
//                                        CopyMemory(bInFirstList, bFirstCard, sizeof(int)* bFirstCount);
//                                        CopyMemory(bInNextList, bNextCard, sizeof(int)* bNextCount);
                                        i = -1;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    return;
                }
                case CT_FIVE_SAME:											//四带一张
                {
                    return;
                }
                case CT_TWO_DOUBLE:												//两对牌型
                {
                    //对原有的两个对子进行保存不允许修改
                    for (int i = 0; i < (bNextCount - 1); i++)
                    {
                        if (GetCardLogicValue(bInNextList[i]) == GetCardLogicValue(bInNextList[i + 1]))
                        {
                            iTemp1 = GetCardLogicValue(bInNextList[i]);
                            break;
                        }
                    }
                    for (int i = bNextCount - 2; i >= 0; i--)
                    {
                        if (GetCardLogicValue(bInNextList[i]) == GetCardLogicValue(bInNextList[i + 1]))
                        {
                            iTemp2 = GetCardLogicValue(bInNextList[i]);
                            break;
                        }
                    }

                    //对剩下的单牌进行置换，在不破坏牌型的情况下将大的单牌放在前面一注
                    for (int i = 0; i < bNextCount; i++)
                    {
                        if (GetCardLogicValue(bInNextList[i]) != iTemp1  && GetCardLogicValue(bInNextList[i]) != iTemp2)
                        {
                            for (int j = bFirstCount - 1; j >= 0; j--)
                            {
                                if (GetCardLogicValue(bInNextList[i]) > GetCardLogicValue(bInFirstList[j]))
                                {
                                    for (int k = 0; k < bFirstCount; k++) {
                                        bFirstCard[k] = bInFirstList[k];
                                    }
                                    for (int k = 0; k < bNextCount; k++) {
                                        bNextCard[k] = bInNextList[k];
                                    }
//                                    CopyMemory(bFirstCard, bInFirstList, sizeof(int)* bFirstCount);
//                                    CopyMemory(bNextCard, bInNextList, sizeof(int)* bNextCount);
                                    bFirstCard[j] = bInNextList[i];
                                    bNextCard[i] = bInFirstList[j];
                                    SortCardList(bFirstCard, bFirstCount, enSortCardType.enDescend);
                                    SortCardList(bNextCard, bNextCount, enSortCardType.enDescend);
                                    if (bFirstType == GetCardType(bFirstCard, bFirstCount, cbMaxCard) &&
                                            bNextType == GetCardType(bNextCard, bNextCount, cbMaxCard))
                                    {
                                        for (int k = 0; k < bFirstCount; k++) {
                                            bInFirstList[k] = bFirstCard[k];
                                        }
                                        for (int k = 0; k < bNextCount; k++) {
                                            bInNextList[k] = bNextCard[k];
                                        }
//                                        CopyMemory(bInFirstList, bFirstCard, sizeof(int)* bFirstCount);
//                                        CopyMemory(bInNextList, bNextCard, sizeof(int)* bNextCount);
                                        i = -1;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                    return;
                }
                case CT_FIVE_THREE_DEOUBLE:										//三条一对
                {
                    //找出对子
                    if (GetCardLogicValue(bInNextList[1]) == GetCardLogicValue(bInNextList[2]))
                    {
                        iTemp1 = GetCardLogicValue(bInNextList[3]);
                    }
                    else
                    {
                        iTemp1 = GetCardLogicValue(bInNextList[1]);
                    }
                    //对对子进行置换，在不破坏牌型的情况下将大的对子放在前面一注
                    for (int i = 0; i < bNextCount - 1; i++)
                    {
                        if (GetCardLogicValue(bInNextList[i]) == iTemp1)
                        {
                            for (int j = bFirstCount - 2; j >= 0; j--)
                            {
                                if (GetCardLogicValue(bInNextList[i]) > GetCardLogicValue(bInFirstList[j]))
                                {
                                    for (int k = 0; k < bFirstCount; k++) {
                                        bFirstCard[k] = bInFirstList[k];
                                    }
                                    for (int k = 0; k < bNextCount; k++) {
                                        bNextCard[k] = bInNextList[k];
                                    }
//                                    CopyMemory(bFirstCard, bInFirstList, sizeof(int)* bFirstCount);
//                                    CopyMemory(bNextCard, bInNextList, sizeof(int)* bNextCount);

                                    bFirstCard[j] = bInNextList[i];
                                    bNextCard[i] = bInFirstList[j];
                                    bFirstCard[j + 1] = bInNextList[i + 1];
                                    bNextCard[i + 1] = bInFirstList[j + 1];

                                    SortCardList(bFirstCard, bFirstCount, enSortCardType.enDescend);
                                    SortCardList(bNextCard, bNextCount, enSortCardType.enDescend);
                                    if (bFirstType == GetCardType(bFirstCard, bFirstCount, cbMaxCard) &&
                                            bNextType == GetCardType(bNextCard, bNextCount, cbMaxCard))
                                    {
                                        for (int k = 0; k < bFirstCount; k++) {
                                            bInFirstList[k] = bFirstCard[k];
                                        }
                                        for (int k = 0; k < bNextCount; k++) {
                                            bInNextList[k] = bNextCard[k];
                                        }
//                                        CopyMemory(bInFirstList, bFirstCard, sizeof(int)* bFirstCount);
//                                        CopyMemory(bInNextList, bNextCard, sizeof(int)* bNextCount);
                                        i = -1;
                                        break;
                                    }
                                }
                            }
                        }
                    }

                    return;
                }
                default:
                {
                    return;
                }
            }
        }
        return;
    }


    /****************************************************
     *函数名：CardTypeToWeights
     *功能：  用于将牌的类型转换成权值输出
     *参数：	 bType		牌类型	IN
     *返回值：int(权值，本函数只对已有的牌型做出相应权值的换算)
     ****************************************************/
    int CardTypeToWeights(int bType, int cbIndex)
    {
        switch (bType)
        {
            case CT_INVALID:													//错误类型
            {
                return -1;
            }
            case CT_SINGLE:														//单牌类型
            {
                return 0;
            }
            case CT_ONE_DOUBLE:													//只有一对
            {
                return 2;
            }
            case CT_TWO_DOUBLE:													//两对牌型
            {
                return 3;
            }
            case CT_THREE:														//三张牌型
            {
                if (1 == cbIndex)
                {
                    return (4 + 3);
                }
                else
                {
                    return 4;
                }

            }
            case CT_FIVE_MIXED_FLUSH_NO_A:										//普通顺子
            {
                return 5;
            }
            case CT_FIVE_MIXED_FLUSH_FIRST_A:									//A前顺子
            {
                return 6;
            }
            case CT_FIVE_MIXED_FLUSH_BACK_A:									//A后顺子
            {
                return 7;
            }
            case CT_FIVE_FLUSH:													//同花
            {
                return 8;
            }
            case CT_FIVE_THREE_DEOUBLE:											//三条一对
            {
                return 9;
            }
            case CT_FIVE_FOUR_ONE:												//四带一张
            {
                if (2 == cbIndex)
                {
                    return (10 + 8);
                }
                if (3 == cbIndex)
                {
                    return (10 + 4);
                }
                else
                {
                    return 10;
                }
            }
            case CT_FIVE_SAME:												//四带一张
            {
                if (3 == cbIndex)
                {
                    return (30 + 8);
                }
                if (4 == cbIndex)
                {
                    return (30 + 4);
                }
                else
                {
                    return 30;
                }
            }
            case CT_FIVE_STRAIGHT_FLUSH_NO_A:									//同花顺牌
            {
                if (2 == cbIndex)
                {
                    return (11 + 10);
                }
                if (3 == cbIndex)
                {
                    return (11 + 5);
                }
                else
                {
                    return 11;
                }
            }
            case CT_FIVE_STRAIGHT_FLUSH_FIRST_A:								//A前同花顺
            {
                if (2 == cbIndex)
                {
                    return (12 + 10);
                }
                if (3 == cbIndex)
                {
                    return (12 + 5);
                }
                else
                {
                    return 12;
                }
            }
            case CT_FIVE_STRAIGHT_FLUSH_BACK_A:									//A后同花顺
            {
                if (2 == cbIndex)
                {
                    return (13 + 10);
                }
                if (3 == cbIndex)
                {
                    return (13 + 5);
                }
                else
                {
                    return 13;
                }
            }
            default:
            {
                return -1;
            }
        }
    }


    //获取类型
    public int GetCardType(int bInCardData[], int bCardCount, int bMaxCardData)
    {
        //数据校验
        //ASSERT(bCardCount == 3 || bCardCount == 5);
        if (bCardCount != 3 && bCardCount != 5) return CT_INVALID;

        bMaxCardData = 0;

        int bCardData[] = new int[5];
        //检查转化
        tagTransData ttdFst = new tagTransData();
        AnalyseMaxTransform(bInCardData, bCardCount, bCardData, ttdFst);
        //分析扑克
        tagAnalyseData AnalyseData = new tagAnalyseData();
        //ZeroMemory(&AnalyseData, sizeof(AnalyseData));
        AnalyseCard(bCardData, bCardCount, AnalyseData);
        SortCardList(bCardData, bCardCount, enSortCardType.enDescend);

        //分析扑克
        tagAnalyseResult AnalyseResult = new tagAnalyseResult();
        //ZeroMemory(&AnalyseResult, sizeof(AnalyseResult));
        AnalysebCardData(bCardData, bCardCount, AnalyseResult);

        //开始分析
        switch (bCardCount)
        {
            case 3:	//三条类型
            {
                //单牌类型
                if (3 == AnalyseData.bOneCount)
                {
                    bMaxCardData = GetCardLogicValue(AnalyseResult.cbCardData[0][0]);
                    return CT_SINGLE;
                }

                //对带一张
                if (1 == AnalyseData.bTwoCount && 1 == AnalyseData.bOneCount)
                {
                    bMaxCardData = GetCardLogicValue(AnalyseResult.cbCardData[1][0]);
                    return CT_ONE_DOUBLE;
                }

                //三张牌型
                if (1 == AnalyseData.bThreeCount)
                {
                    bMaxCardData = GetCardLogicValue(AnalyseResult.cbCardData[2][0]);
                    return CT_THREE;
                }

				/*if (1 == AnalyseData.bTwoCount && AnalyseData.bSameColor)
				{
				bMaxCardData = GetCardLogicValue(AnalyseResult.cbCardData[1][0]);
				//CString cc;
				//cc.Format(_T("对子花>> %d  %d  %d"), GetCardLogicValue(AnalyseResult.cbCardData[0][0]), GetCardLogicValue(AnalyseResult.cbCardData[1][0]), GetCardLogicValue(AnalyseResult.cbCardData[2][0]));
				//CTraceService::TraceString(cc, TraceLevel_Debug);
				return CT_FIVE_FLUSH_DOUBLE; //所谓的对子花, 如果头道不需要的话, 注释掉即可
				}*/
                //错误类型
                return CT_INVALID;
            }
            case 5:	//五张牌型
            {
                boolean bFlushNoA = false;
                boolean bFlushFirstA = false;
                boolean bFlushBackA = false;

                //A连在后
                if (14 == GetCardLogicValue(bCardData[0]) && 10 == GetCardLogicValue(bCardData[4]))
                    bFlushBackA = true;
                else
                    bFlushNoA = true;
                for (int i = 0; i < 4; ++i)
                {
                    if (1 != GetCardLogicValue(bCardData[i]) - GetCardLogicValue(bCardData[i + 1]))
                    {
                        bFlushBackA = false;
                        bFlushNoA = false;
                    }
                }

                //A连在前
                if (false == bFlushBackA && false == bFlushNoA && 14 == GetCardLogicValue(bCardData[0]))
                {
                    bFlushFirstA = true;
                    for (int i = 1; i < 4; ++i)
                        if (1 != GetCardLogicValue(bCardData[i]) - GetCardLogicValue(bCardData[i + 1]))
                            bFlushFirstA = false;
                    if (2 != GetCardLogicValue(bCardData[4]))
                        bFlushFirstA = false;
                }

                //同花五牌
                if (false == bFlushBackA && false == bFlushNoA && false == bFlushFirstA)
                {
                    if (true == AnalyseData.bSameColor)
                    {
//                        CString cc;
                        bMaxCardData = GetCardLogicValue(AnalyseResult.cbCardData[0][0]);
                        if (AnalyseData.bTwoCount == 1)
                        {
                            //cc.Format(_T("对子花>> %d  %d  %d  %d  %d"),GetCardLogicValue(AnalyseResult.cbCardData[0][0]), GetCardLogicValue(AnalyseResult.cbCardData[1][0]), GetCardLogicValue(AnalyseResult.cbCardData[2][0]), GetCardLogicValue(AnalyseResult.cbCardData[3][0]), GetCardLogicValue(AnalyseResult.cbCardData[4][0]));
                            //CTraceService::TraceString(cc, TraceLevel_Debug);
                            return CT_FIVE_FLUSH_DOUBLE;
                        }
                        else if (AnalyseData.bTwoCount == 2)
                        {
                            return CT_FIVE_FLUSH_TWO_DOUBLE;
                        }
                        else
                        {
                            //四带单张
                            if (1 == AnalyseData.bFourCount && 1 == AnalyseData.bOneCount)
                            {
                                bMaxCardData = GetCardLogicValue(AnalyseResult.cbCardData[3][0]);
                                return	 CT_FIVE_FOUR_ONE;
                            }
                            return CT_FIVE_FLUSH;
                        }

                    }
                }
                else if (true == bFlushNoA)
                {
                    bMaxCardData = GetCardLogicValue(AnalyseResult.cbCardData[0][0]);
                    //杂顺类型
                    if (false == AnalyseData.bSameColor) return CT_FIVE_MIXED_FLUSH_NO_A;
                        //同花顺牌
                    else							  return CT_FIVE_STRAIGHT_FLUSH_NO_A;
                }
                else if (true == bFlushFirstA)
                {
                    bMaxCardData = GetCardLogicValue(AnalyseResult.cbCardData[0][0]);
                    //杂顺类型
                    if (false == AnalyseData.bSameColor) return CT_FIVE_MIXED_FLUSH_FIRST_A;
                        //同花顺牌
                    else							  return CT_FIVE_STRAIGHT_FLUSH_FIRST_A;
                }
                else if (true == bFlushBackA)
                {
                    bMaxCardData = GetCardLogicValue(AnalyseResult.cbCardData[0][0]);
                    //杂顺类型
                    if (false == AnalyseData.bSameColor) return CT_FIVE_MIXED_FLUSH_BACK_A;
                        //同花顺牌
                    else							  return CT_FIVE_STRAIGHT_FLUSH_BACK_A;
                }

                //四带单张
                if (1 == AnalyseData.bFourCount && 1 == AnalyseData.bOneCount)
                {
                    bMaxCardData = GetCardLogicValue(AnalyseResult.cbCardData[3][0]);
                    return	 CT_FIVE_FOUR_ONE;
                }
                if (1 == AnalyseData.bFiveCount)
                {
                    bMaxCardData = GetCardLogicValue(AnalyseResult.cbCardData[4][0]);
                    return	 CT_FIVE_SAME;
                }

                //三条一对
                if (1 == AnalyseData.bThreeCount && 1 == AnalyseData.bTwoCount)
                {
                    bMaxCardData = GetCardLogicValue(AnalyseResult.cbCardData[2][0]);
                    return	 CT_FIVE_THREE_DEOUBLE;
                }

                //三条带单
                if (1 == AnalyseData.bThreeCount && 2 == AnalyseData.bOneCount)
                {
                    bMaxCardData = GetCardLogicValue(AnalyseResult.cbCardData[2][0]);
                    return	 CT_THREE;
                }

                //两对牌型
                if (2 == AnalyseData.bTwoCount && 1 == AnalyseData.bOneCount)
                {
                    bMaxCardData = GetCardLogicValue(AnalyseResult.cbCardData[1][0]);
                    return	 CT_TWO_DOUBLE;
                }

                //只有一对
                if (1 == AnalyseData.bTwoCount && 3 == AnalyseData.bOneCount)
                {
                    bMaxCardData = GetCardLogicValue(AnalyseResult.cbCardData[1][0]);
                    return	 CT_ONE_DOUBLE;
                }

                //单牌类型
                if (5 == AnalyseData.bOneCount && false == AnalyseData.bSameColor)
                {
                    bMaxCardData = GetCardLogicValue(AnalyseResult.cbCardData[0][0]);
                    return  CT_SINGLE;
                }

                //错误类型
                return CT_INVALID;
            }
        }

        return CT_INVALID;
    }

    //判断特殊牌型
//必须是13张
    int GetSpecialType(int bHandCardData[], int bCardCount)
    {
        //ASSERT(bCardCount == HAND_CARD_COUNT);
        if (bCardCount != HAND_CARD_COUNT) return CT_EX_INVALID;

        //排列扑克
        int bCardData[] = new int[13];
        for (int i = 0; i < 13; i++) {
            bCardData[i] = bHandCardData[i];
        }
//        CopyMemory(bCardData, bHandCardData, sizeof(int)* 13);
        //排序扑克
        SortCardList(bCardData, bCardCount, enSortCardType.enDescend);

        //设置结果
        tagAnalyseData AnalyseData = new tagAnalyseData();
        //ZeroMemory(&AnalyseData, sizeof(AnalyseData));

        //变量定义
        int bSameCount = 1,
                bCardValueTemp = 0,
                bFirstCardIndex = 0;	//记录下标

        int bLogicValue = GetCardLogicValue(bCardData[0]);
        int bCardColor = GetCardColor(bCardData[0]);
        //zhaozw 有王不算三同花
        if (bCardColor == 4)
        {
            return CT_EX_INVALID;
        }
        //////////////////////////////////////////////////////////////////////////
        //扑克分析
        for (int i = 1; i < bCardCount; i++)
        {
            //获取扑克
            bCardValueTemp = GetCardLogicValue(bCardData[i]);
            if (bCardValueTemp == bLogicValue) bSameCount++;

            //保存结果
            if ((bCardValueTemp != bLogicValue) || (i == (bCardCount - 1)))
            {
                switch (bSameCount)
                {
                    case 1:		//一张
                        break;
                    case 2:		//两张
                    {
                        AnalyseData.bTwoFirst[AnalyseData.bTwoCount] = bFirstCardIndex;
                        AnalyseData.bTwoCount++;
                        break;
                    }
                    case 3:		//三张
                    {
                        AnalyseData.bThreeFirst[AnalyseData.bThreeCount] = bFirstCardIndex;
                        AnalyseData.bThreeCount++;
                        break;
                    }
                    case 4:		//四张
                    {
                        AnalyseData.bFourFirst[AnalyseData.bFourCount] = bFirstCardIndex;
                        AnalyseData.bFourCount++;
                        break;
                    }
                    case 5:		//5张
                    {
                        AnalyseData.bFiveFirst[AnalyseData.bFiveCount] = bFirstCardIndex;
                        AnalyseData.bFiveCount++;
                        break;
                    }
                    case 6:		//6张
                    {
                        AnalyseData.bSixFirst[AnalyseData.bSixCount] = bFirstCardIndex;
                        AnalyseData.bSixCount++;
                        break;
                    }
                    default:
                    break;
                }
            }

            //设置变量
            if (bCardValueTemp != bLogicValue)
            {
                if (bSameCount == 1)
                {
                    if (i != bCardCount - 1)
                    {
                        AnalyseData.bOneFirst[AnalyseData.bOneCount] = bFirstCardIndex;
                        AnalyseData.bOneCount++;
                    }
                    else
                    {
                        AnalyseData.bOneFirst[AnalyseData.bOneCount] = bFirstCardIndex;
                        AnalyseData.bOneCount++;
                        AnalyseData.bOneFirst[AnalyseData.bOneCount] = i;
                        AnalyseData.bOneCount++;
                    }
                }
                else
                {
                    if (i == bCardCount - 1)
                    {
                        AnalyseData.bOneFirst[AnalyseData.bOneCount] = i;
                        AnalyseData.bOneCount++;
                    }
                }
                bSameCount = 1;
                bLogicValue = bCardValueTemp;
                bFirstCardIndex = i;
            }
        }
        if (m_cbCity == 0)
        {
            //至尊青龙
            if (IsStraightDragon(bCardData, bCardCount) == true)
                return CT_EX_ZHIZUNQINGLONG;

            //一条龙
            if ((IsLinkCard(bCardData, bCardCount) == true))
                return CT_EX_YITIAOLONG;

            //十二皇族 最小的大于等于J
            if (GetCardLogicValue(bCardData[bCardCount - 1]) >= 11)
            {
                return CT_EX_SHIERHUANGZU;
            }

            while (true)
            {
                //三同花顺
                int cbSameCardCount[] = new int[4];
                //ZeroMemory(cbSameCardCount, sizeof(cbSameCardCount));
                int cbSameCardData[][] = new int[4][13];
                //ZeroMemory(cbSameCardData, sizeof(cbSameCardData));

                //统计花色
                for (int i = 0; i < bCardCount; i++)
                {
                    //获取花色
                    int cbCardColor = GetCardColor(bCardData[i]);
                    //zhaozw 有王不算三同花
                    if (cbCardColor == 4)
                    {
                        return CT_EX_INVALID;
                    }
                    //原牌数目
                    int cbCount = cbSameCardCount[cbCardColor];
                    //追加扑克
                    cbSameCardData[cbCardColor][cbCount] = bCardData[i];
                    cbSameCardCount[cbCardColor] = cbSameCardCount[cbCardColor] + 1;
                }

                //三同花顺
                boolean bCondition = true;
                for (int i = 0; i < 4; i++)
                {
                    if ((cbSameCardCount[i] % 5) != 0 && (cbSameCardCount[i] % 5) != 3)
                    {
                        bCondition = false;
                        break;
                    }
                }

                if (bCondition == false) break;

                //判断顺子
                for (int i = 0; i < 4; i++)
                {
                    if (cbSameCardCount[i] == 3)
                    {
                        if (IsLinkCard(cbSameCardData[i], cbSameCardCount[i]) == false)
                        {
                            bCondition = false;
                            break;
                        }
                    }
                    else if (cbSameCardCount[i] == 5)
                    {
                        if (IsLinkCard(cbSameCardData[i], cbSameCardCount[i]) == false)
                        {
                            bCondition = false;
                            break;
                        }
                    }
                    else if (cbSameCardCount[i] == 8 || cbSameCardCount[i] == 10)
                    {
                        int cbLineCardData[][] = new int[3][5];
                        boolean setvalue = SetLinkCard(cbSameCardData[i], cbSameCardCount[i], cbLineCardData);
                        if (setvalue == false)
                        {
                            bCondition = false;
                            break;
                        }
                    }
                }
                if (bCondition == true)
                {
                    //return CT_EX_SANTONGHUASHUN;
                }
                break;
            }

            //三分天下
            if (AnalyseData.bFourCount == 3 && AnalyseData.bOneCount == 1 || (AnalyseData.bFourCount + AnalyseData.bFiveCount == 3))
                return CT_EX_SANFENGTIANXIA;

            //6tong
            if (AnalyseData.bSixCount >= 1)
                return CT_SIX_SAME;
            //全大
            if (GetCardLogicValue(bCardData[bCardCount - 1]) >= 8)
            {
                return CT_EX_QUANDA;
            }
            //全xiao
            if (GetCardLogicValue(bCardData[0]) <= 8)
            {
                return CT_EX_QUANXIAO;
            }
            int colornum[] = new int[2];
            int laotou = 0;

            for (int i = 0; i < bCardCount; i++)
            {
                //获取花色
                int cbCardColor = GetCardColor(bCardData[i]);
                int cbCardValue = GetCardLogicValue(bCardData[i]);
                if (cbCardColor == 0 || cbCardColor == 2)
                {
                    colornum[0]++;
                }
                else{
                    colornum[1]++;
                }
                if (cbCardValue == 11 || cbCardValue == 12 || cbCardValue == 13)
                {
                    laotou++;
                }
            }
            if (colornum[0] == 13 || colornum[1] == 13)
            {
                return CT_COUYISE;
            }
            if (colornum[0] == 12)
            {
                return CT_EX_QUANHONG1HEI;
            }
            if (colornum[1] == 12)
            {
                return CT_EX_QUANHEI1HONG;
            }

            //四套三条
            //if (AnalyseData.bThreeCount == 4 && AnalyseData.bOneCount == 1 || AnalyseData.bThreeCount == 3 && AnalyseData.bFourCount == 1)
            //	return CT_EX_SITAOSANTIAO;

            if (AnalyseData.bTwoCount == 5 && AnalyseData.bThreeCount == 1 || AnalyseData.bTwoCount == 3 && AnalyseData.bFourCount == 1 && AnalyseData.bThreeCount == 1 || AnalyseData.bTwoCount == 1 && AnalyseData.bFourCount == 2 && AnalyseData.bThreeCount == 1)
                return CT_EX_WUDUISANTIAO;

            if (laotou >= 7)
            {
                return CT_EX_QILAOTOU;
            }

            //六对半
            if (AnalyseData.bTwoCount == 6 && AnalyseData.bOneCount == 1 || AnalyseData.bTwoCount == 4 && AnalyseData.bFourCount == 1 && AnalyseData.bOneCount == 1 || AnalyseData.bTwoCount == 2 && AnalyseData.bFourCount == 2 && AnalyseData.bOneCount == 1
                    || (AnalyseData.bOneCount + AnalyseData.bThreeCount + AnalyseData.bFiveCount)>0)
                return CT_EX_LIUDUIBAN;

            //三顺子
            int cbLineCardData[][] = new int[3][5];
            boolean setvalue = SetLinkCard(bCardData, bCardCount, cbLineCardData);
            if (setvalue == true)
            {
                return CT_EX_SANSHUNZI;
            }

            //三同花
            while (true)
            {
                //三同花
                int cbSameCardCount[] = new int[4];
                //ZeroMemory(cbSameCardCount, sizeof(cbSameCardCount));
                int cbSameCardData[][] = new int[4][13];
                //ZeroMemory(cbSameCardData, sizeof(cbSameCardData));

                //统计花色
                for (int i = 0; i < bCardCount; i++)
                {
                    //获取花色
                    int cbCardColor = GetCardColor(bCardData[i]);
                    //zhaozw 有王不算三同花
                    if (cbCardColor == 4)
                    {
                        return CT_EX_INVALID;
                    }
                    //原牌数目
                    int cbCount = cbSameCardCount[cbCardColor];
                    //追加扑克
                    cbSameCardData[cbCardColor][cbCount] = bCardData[i];
                    cbSameCardCount[cbCardColor] = cbSameCardCount[cbCardColor] + 1;
                }

                //三同花
                boolean bCondition = true;
                for (int i = 0; i < 4; i++)
                {
                    if ((cbSameCardCount[i] % 5) != 0 && (cbSameCardCount[i] % 5) != 3)
                    {
                        bCondition = false;
                        break;
                    }
                }

                if (bCondition == true)
                {
                    return CT_EX_SANTONGHUA;
                }
                break;
            }

        }
        else if (m_cbCity == 1)
        {
            //至尊青龙
            if (IsStraightDragon(bCardData, bCardCount) == true)
                return CT_EX_YITIAOLONG;

            //一条龙
            if ((IsLinkCard(bCardData, bCardCount) == true))
                return CT_EX_YITIAOLONG;

            while (true)
            {
                //三同花顺
                int cbSameCardCount[] = new int[4];
                //ZeroMemory(cbSameCardCount, sizeof(cbSameCardCount));
                int cbSameCardData[][] = new int[4][13];
                //ZeroMemory(cbSameCardData, sizeof(cbSameCardData));

                //统计花色
                for (int i = 0; i < bCardCount; i++)
                {
                    //获取花色
                    int cbCardColor = GetCardColor(bCardData[i]);
                    //zhaozw 有王不算三同花
                    if (cbCardColor == 4)
                    {
                        return CT_EX_INVALID;
                    }
                    //原牌数目
                    int cbCount = cbSameCardCount[cbCardColor];
                    //追加扑克
                    cbSameCardData[cbCardColor][cbCount] = bCardData[i];
                    cbSameCardCount[cbCardColor] = cbSameCardCount[cbCardColor] + 1;
                }

                //三同花顺
                boolean bCondition = true;
                for (int i = 0; i < 4; i++)
                {
                    if ((cbSameCardCount[i] % 5) != 0 && (cbSameCardCount[i] % 5) != 3)
                    {
                        bCondition = false;
                        break;
                    }
                }

                if (bCondition == false) break;

                //判断顺子
                for (int i = 0; i < 4; i++)
                {
                    if (cbSameCardCount[i] == 3)
                    {
                        if (IsLinkCard(cbSameCardData[i], cbSameCardCount[i]) == false)
                        {
                            bCondition = false;
                            break;
                        }
                    }
                    else if (cbSameCardCount[i] == 5)
                    {
                        if (IsLinkCard(cbSameCardData[i], cbSameCardCount[i]) == false)
                        {
                            bCondition = false;
                            break;
                        }
                    }
                    else if (cbSameCardCount[i] == 8 || cbSameCardCount[i] == 10)
                    {
                        int cbLineCardData[][] = new int[3][5];
                        boolean setvalue = SetLinkCard(cbSameCardData[i], cbSameCardCount[i], cbLineCardData);
                        if (setvalue == false)
                        {
                            bCondition = false;
                            break;
                        }
                    }
                }
                if (bCondition == true)
                {
                    //return CT_EX_SANTONGHUASHUN;
                }
                break;
            }

            //三分天下
            if (AnalyseData.bFourCount == 3 && AnalyseData.bOneCount == 1 || (AnalyseData.bFourCount + AnalyseData.bFiveCount == 3))
                return CT_EX_SANFENGTIANXIA;

            //四套三条
            //if (AnalyseData.bThreeCount == 4 && AnalyseData.bOneCount == 1 || AnalyseData.bThreeCount == 3 && AnalyseData.bFourCount == 1)
            //	return CT_EX_SITAOSANTIAO;

            //六对半
            if (AnalyseData.bTwoCount == 6 && AnalyseData.bOneCount == 1 || AnalyseData.bTwoCount == 4 && AnalyseData.bFourCount == 1 && AnalyseData.bOneCount == 1 || AnalyseData.bTwoCount == 2 && AnalyseData.bFourCount == 2 && AnalyseData.bOneCount == 1
                    || (AnalyseData.bOneCount + AnalyseData.bThreeCount + AnalyseData.bFiveCount == 1))
                return CT_EX_LIUDUIBAN;

            //三顺子
            int cbLineCardData[][] = new int[3][5];
            boolean setvalue = SetLinkCard(bCardData, bCardCount, cbLineCardData);
            if (setvalue == true)
            {
                return CT_EX_SANSHUNZI;
            }

            //三同花
            while (true)
            {
                //三同花
                int cbSameCardCount[] = new int[4];
                //ZeroMemory(cbSameCardCount, sizeof(cbSameCardCount));
                int cbSameCardData[][] = new int[4][13];
                //ZeroMemory(cbSameCardData, sizeof(cbSameCardData));

                //统计花色
                for (int i = 0; i < bCardCount; i++)
                {
                    //获取花色
                    int cbCardColor = GetCardColor(bCardData[i]);
                    //zhaozw 有王不算三同花
                    if (cbCardColor == 4)
                    {
                        return CT_EX_INVALID;
                    }
                    //原牌数目
                    int cbCount = cbSameCardCount[cbCardColor];
                    //追加扑克
                    cbSameCardData[cbCardColor][cbCount] = bCardData[i];
                    cbSameCardCount[cbCardColor] = cbSameCardCount[cbCardColor] + 1;
                }

                //三同花
                boolean bCondition = true;
                for (int i = 0; i < 4; i++)
                {
                    if ((cbSameCardCount[i] % 5) != 0 && (cbSameCardCount[i] % 5) != 3)
                    {
                        bCondition = false;
                        break;
                    }
                }

                if (bCondition == true)
                {
                    return CT_EX_SANTONGHUA;
                }
                break;
            }
        }
        else{
            //一条龙
            if ((IsLinkCard(bCardData, bCardCount) == true))
                return CT_EX_YITIAOLONG;

            while (true)
            {
                //三同花顺
                int cbSameCardCount[] = new int[4];
                //ZeroMemory(cbSameCardCount, sizeof(cbSameCardCount));
                int cbSameCardData[][] = new int[4][13];
                //ZeroMemory(cbSameCardData, sizeof(cbSameCardData));

                //统计花色
                for (int i = 0; i < bCardCount; i++)
                {
                    //获取花色
                    int cbCardColor = GetCardColor(bCardData[i]);
                    //zhaozw 有王不算三同花
                    if (cbCardColor == 4)
                    {
                        return CT_EX_INVALID;
                    }
                    //原牌数目
                    int cbCount = cbSameCardCount[cbCardColor];
                    //追加扑克
                    cbSameCardData[cbCardColor][cbCount] = bCardData[i];
                    cbSameCardCount[cbCardColor] = cbSameCardCount[cbCardColor] + 1;
                }

                //三同花顺
                boolean bCondition = true;
                for (int i = 0; i < 4; i++)
                {
                    if ((cbSameCardCount[i] % 5) != 0 && (cbSameCardCount[i] % 5) != 3)
                    {
                        bCondition = false;
                        break;
                    }
                }

                if (bCondition == false) break;

                //判断顺子
                for (int i = 0; i < 4; i++)
                {
                    if (cbSameCardCount[i] == 3)
                    {
                        if (IsLinkCard(cbSameCardData[i], cbSameCardCount[i]) == false)
                        {
                            bCondition = false;
                            break;
                        }
                    }
                    else if (cbSameCardCount[i] == 5)
                    {
                        if (IsLinkCard(cbSameCardData[i], cbSameCardCount[i]) == false)
                        {
                            bCondition = false;
                            break;
                        }
                    }
                    else if (cbSameCardCount[i] == 8 || cbSameCardCount[i] == 10)
                    {
                        int cbLineCardData[][] = new int[3][5];
                        boolean setvalue = SetLinkCard(cbSameCardData[i], cbSameCardCount[i], cbLineCardData);
                        if (setvalue == false)
                        {
                            bCondition = false;
                            break;
                        }
                    }
                }
                if (bCondition == true)
                {
                    //return CT_EX_SANTONGHUASHUN;
                }
                break;
            }
            int colornum[] = new int[2];
            int laotou = 0;

            for (int i = 0; i < bCardCount; i++)
            {
                //获取花色
                int cbCardColor = GetCardColor(bCardData[i]);
                int cbCardValue = GetCardLogicValue(bCardData[i]);
                if (cbCardColor == 0 || cbCardColor == 2)
                {
                    colornum[0]++;
                }
                else{
                    colornum[1]++;
                }
                if (cbCardValue == 11 || cbCardValue == 12 || cbCardValue == 13)
                {
                    laotou++;
                }
            }
            if (colornum[0] == 13)
            {
                return CT_EX_QUANHONG;
            }
            if (colornum[1] == 13)
            {
                return CT_EX_QUANHEI;
            }
            if (colornum[0] == 12)
            {
                return CT_EX_QUANHONG1HEI;
            }
            if (colornum[1] == 12)
            {
                return CT_EX_QUANHEI1HONG;
            }

            if (laotou >= 9)
            {
                return CT_EX_JIULAOTOU;
            }

            if (laotou >= 8)
            {
                return CT_EX_BALAOTOU;
            }

            if (laotou >= 7)
            {
                return CT_EX_QILAOTOU;
            }

            //全大
            if (GetCardLogicValue(bCardData[bCardCount - 1]) >= 8)
            {
                return CT_EX_QUANDA;
            }
            //全xiao
            if (GetCardLogicValue(bCardData[0]) <= 8)
            {
                return CT_EX_QUANXIAO;
            }

            //六对半
            if (AnalyseData.bTwoCount == 6 && AnalyseData.bOneCount == 1 || AnalyseData.bTwoCount == 4 && AnalyseData.bFourCount == 1 && AnalyseData.bOneCount == 1 || AnalyseData.bTwoCount == 2 && AnalyseData.bFourCount == 2 && AnalyseData.bOneCount == 1
                    || (AnalyseData.bOneCount + AnalyseData.bThreeCount + AnalyseData.bFiveCount)>0)
                return CT_EX_LIUDUIBAN;

            //三顺子
            int cbLineCardData[][] = new int[3][5];
            boolean setvalue = SetLinkCard(bCardData, bCardCount, cbLineCardData);
            if (setvalue == true)
            {
                return CT_EX_SANSHUNZI;
            }

            //三同花
            while (true)
            {
                //三同花
                int cbSameCardCount[] = new int[4];
                //ZeroMemory(cbSameCardCount, sizeof(cbSameCardCount));
                int cbSameCardData[][] = new int[4][13];
                //ZeroMemory(cbSameCardData, sizeof(cbSameCardData));

                //统计花色
                for (int i = 0; i < bCardCount; i++)
                {
                    //获取花色
                    int cbCardColor = GetCardColor(bCardData[i]);
                    //zhaozw 有王不算三同花
                    if (cbCardColor == 4)
                    {
                        return CT_EX_INVALID;
                    }
                    //原牌数目
                    int cbCount = cbSameCardCount[cbCardColor];
                    //追加扑克
                    cbSameCardData[cbCardColor][cbCount] = bCardData[i];
                    cbSameCardCount[cbCardColor] = cbSameCardCount[cbCardColor] + 1;
                }

                //三同花
                boolean bCondition = true;
                for (int i = 0; i < 4; i++)
                {
                    if ((cbSameCardCount[i] % 5) != 0 && (cbSameCardCount[i] % 5) != 3)
                    {
                        bCondition = false;
                        break;
                    }
                }

                if (bCondition == true)
                {
                    return CT_EX_SANTONGHUA;
                }
                break;
            }
        }
        //////////////////////////////////////////////////////////////////////////

        //非特殊牌
        return CT_EX_INVALID;
    }

    //获取特殊牌型排序索引值
    void GetSpecialTypeSort(int bSpecialType[], int SpecialTypeIndex[], int PlayerCount){
        //bSpecialType
        int n = PlayerCount;// sizeof(bSpecialType);
        //int bSpecialType[n] = { 23, 45, 1, 8, 6, 666 };
        int k;
        int t;
        for (int i = 0; i < n; i++)
        {
            SpecialTypeIndex[i] = i;
        }
        //保存牌型索引值从小到大
        //int SpecialTypeIndex[n] = { 0, 1, 2, 3, 4, 5 };
        for (k = 1; k < n; k++)//6个数共需要比较5回
        {
            for (int j = 0; j < (n - k); j++)//第一回比较要比较6个数即5次，第二回是5个数4次...第k回是n-k次??若j从1开始，则j<=(n-k)，j从0开始，则j<(n-k);
            {
                //if (bSpecialType[j] > 14 && bSpecialType[j + 1]>14)
                //{
                if (bSpecialType[j] > bSpecialType[j + 1])
                {
                    t = bSpecialType[j];
                    bSpecialType[j] = bSpecialType[j + 1];
                    bSpecialType[j + 1] = t;
                    int y = SpecialTypeIndex[j];
                    SpecialTypeIndex[j] = SpecialTypeIndex[j + 1];
                    SpecialTypeIndex[j + 1] = y;
                }
                //}
            }
        }
    }
    //获取对子排序索引值
    void GetTwoSort(int[] bPutCardData, tagAnalyseData AnalyseData, int TwoIndex[], int ATwoCount) {
        //tagAnalyseData AnalyseData;
        ////ZeroMemory(&AnalyseData, sizeof(tagAnalyseData));
        //CopyMemory(AnalyseData, &YAnalyseData, sizeof(YAnalyseData));
        int n = ATwoCount;// sizeof(bSpecialType);
        int k;
        int t;
        for (int i = 0; i < n; i++)
        {
            TwoIndex[i] = i;
        }
        //保存牌型索引值从小到大
        //int SpecialTypeIndex[n] = { 0, 1, 2, 3, 4, 5 };
        for (k = 1; k < AnalyseData.bTwoCount; k++)//6个数共需要比较5回
        {
            for (int j = 0; j < (n - k); j++)//第一回比较要比较6个数即5次，第二回是5个数4次...第k回是n-k次??若j从1开始，则j<=(n-k)，j从0开始，则j<(n-k);
            {
                //if (bSpecialType[j] > 14 && bSpecialType[j + 1]>14)
                //{
                int sz1 = GetCardLogicValue(bPutCardData[AnalyseData.bTwoFirst[j]]);
                int sz2 = GetCardLogicValue(bPutCardData[AnalyseData.bTwoFirst[j + 1]]);
                if (sz1 > sz2)
                {
                    t = AnalyseData.bTwoFirst[j];
                    AnalyseData.bTwoFirst[j] = AnalyseData.bTwoFirst[j + 1];
                    AnalyseData.bTwoFirst[j + 1] = t;
                    int y = TwoIndex[j];
                    TwoIndex[j] = TwoIndex[j + 1];
                    TwoIndex[j + 1] = y;
                }
                //}
            }
        }
    }


    //是否顺子
    boolean IsLinkCard( int cbCardData[], int cbCardCount)
    {
        //ASSERT(cbCardCount > 0);
        if (cbCardCount <= 0) return false;

        boolean bRet = true;
        int cbCardBuffer[] = new int[13];
        for (int i = 0; i < 13; i++) {
            cbCardBuffer[i] = cbCardData[i];
        }
//        CopyMemory(cbCardBuffer, cbCardData, sizeof(int)*cbCardCount);

        //降序排列
        SortCardList(cbCardBuffer, cbCardCount, enSortCardType.enDescend);

        int cbFirstCard = GetCardLogicValue(cbCardBuffer[0]);
        for (int i = 1; i<cbCardCount; i++)
        {
            int cbNextCard = GetCardLogicValue(cbCardBuffer[i]);
            if (cbFirstCard != cbNextCard + i) bRet = false;
        }

        //A前顺子单独处理
        if (bRet == false && cbFirstCard == 14)
        {
            if (GetCardLogicValue(cbCardBuffer[cbCardCount - 1]) != 2)
            {
                return bRet;
            }
            else
            {
                cbFirstCard = GetCardLogicValue(cbCardBuffer[1]);
                for (int i = 2; i < cbCardCount; i++)
                {
                    int cbNextCard = GetCardLogicValue(cbCardBuffer[i]);
                    if (cbFirstCard != (cbNextCard + i - 1)) return false;
                }
                return true;
            }
        }

        return bRet;
    }

    //是否同花
    boolean IsSameColorCard( int cbCardData[], int cbCardCount)
    {
        //ASSERT(cbCardCount > 0);
        if (cbCardCount <= 0) return false;

        boolean bRet = true;

        int cbFirstCard = GetCardColor(cbCardData[0]);
        for (int i = 1; i < cbCardCount; i++)
        {
            int cbNextCard = GetCardColor(cbCardData[i]);
            if (cbNextCard != cbFirstCard) bRet = false;
        }

        return bRet;
    }

    //是否同花顺
    boolean IsStraightDragon( int cbCardData[], int bCardCount)
    {
        //校验数据
        //ASSERT(bCardCount>0 && bCardCount <= 13);
        if (bCardCount <= 0 || bCardCount>13)	return false;

        boolean b1 = IsLinkCard(cbCardData, bCardCount);
        boolean b2 = IsSameColorCard(cbCardData, bCardCount);
        if (b1 == false || b2 == false)
            return false;

        return true;
    }

    //获取对数
    int GetDoubleCount(int cbFrontCard[], int cbMidCard[], int cbBackCard[])
    {
        tagAnalyseData AanlyseFront = new tagAnalyseData(), AnalyseMid = new tagAnalyseData(), AnalyeBack = new tagAnalyseData();
        //ZeroMemory(&AanlyseFront, sizeof(AanlyseFront));
        //ZeroMemory(&AnalyseMid, sizeof(AnalyseMid));
        //ZeroMemory(&AnalyeBack, sizeof(AnalyeBack));

        AnalyseCard(cbFrontCard, 3, AanlyseFront);
        AnalyseCard(cbMidCard, 5, AnalyseMid);
        AnalyseCard(cbBackCard, 5, AnalyeBack);

        if ((AanlyseFront.bTwoCount == 1) && (AnalyseMid.bTwoCount == 2) && (AnalyeBack.bTwoCount == 2))
        {
            if ((GetCardLogicValue(cbFrontCard[AanlyseFront.bOneFirst[0]]) == GetCardLogicValue(cbMidCard[AnalyseMid.bOneFirst[0]])) ||
                    (GetCardLogicValue(cbMidCard[AnalyseMid.bOneFirst[0]]) == GetCardLogicValue(cbBackCard[AnalyeBack.bOneFirst[0]])) ||
                    (GetCardLogicValue(cbFrontCard[AanlyseFront.bOneFirst[0]]) == GetCardLogicValue(cbBackCard[AnalyeBack.bOneFirst[0]])))
                return 6;
        }

        return AanlyseFront.bTwoCount + AnalyseMid.bTwoCount + AnalyeBack.bTwoCount;
    }

    //设置顺子
    boolean SetLinkCard(int cbCardData[], int cbCardCount, int cbLineCardData[][])
    {
        if (cbCardCount % 5 != 0 && cbCardCount % 5 != 3)
            return false;

        tagSearchCardResult LineCardResult = new tagSearchCardResult();

        int cbLineCardResult5 = SearchLineCardType(cbCardData, cbCardCount, 5, LineCardResult);
        if (cbLineCardResult5 < 1) return false;
        for (int i = 0; i < cbLineCardResult5; i++)
        {
            int cbTempCardData[] = new int[13];
            int cbTempCount = cbCardCount;

            boolean value = RemoveCard(LineCardResult.cbResultCard[i], LineCardResult.cbCardCount[i], cbCardData, cbTempCardData, cbTempCount);
            cbTempCount -= LineCardResult.cbCardCount[i];
            if (cbTempCount == 8)
            {
                while (true)
                {
                    int LineData[][] = new int[3][5];
                    boolean setResult = SetLinkCard(cbTempCardData, cbTempCount, LineData);
                    if (setResult == false) break;
                    for (int cbindex = 0; cbindex < 5; cbindex++)
                    {
                        cbLineCardData[0][cbindex] = LineData[0][cbindex];
                        cbLineCardData[1][cbindex] = LineData[1][cbindex];
                        cbLineCardData[2][cbindex] = LineCardResult.cbResultCard[i][cbindex];
                    }
                    return true;
                }
            }

            if (IsLinkCard(cbTempCardData, cbTempCount) == true)
            {
                //八张牌，放前中墩
                if (cbTempCount == 3)
                {
                    for (int cbindex = 0; cbindex < 3; cbindex++)
                    {
                        cbLineCardData[0][cbindex] = cbTempCardData[cbindex];
                    }
                    for (int cbindex = 0; cbindex < LineCardResult.cbCardCount[i]; cbindex++)
                    {
                        cbLineCardData[1][cbindex] = LineCardResult.cbResultCard[i][cbindex];
                    }
                }
                //十张，放中后墩
                else
                {
                    for (int cbindex = 0; cbindex < 3; cbindex++)
                    {
                        cbLineCardData[1][cbindex] = cbTempCardData[cbindex];
                    }
                    for (int cbindex = 0; cbindex < LineCardResult.cbCardCount[i]; cbindex++)
                    {
                        cbLineCardData[2][cbindex] = LineCardResult.cbResultCard[i][cbindex];
                    }
                }
                return true;
            }
        }
        return false;
    }

    //分析扑克
    void AnalyseCard( int bCardDataList[],  int bCardCount, tagAnalyseData AnalyseData)
    {
        //ASSERT(3 == bCardCount || 5 == bCardCount);

        //排列扑克
        int bCardData[] = new int[13];
        for (int i = 0; i < bCardCount; i++) {
            bCardData[i] = bCardDataList[i];
        }
//        CopyMemory(bCardData, bCardDataList, bCardCount);
        SortCardList(bCardData, bCardCount, enSortCardType.enDescend);

        //变量定义
        int bSameCount = 1,
                bCardValueTemp = 0,
                bSameColorCount = 1,
                bFirstCardIndex = 0;	//记录下标

        int bLogicValue = GetCardLogicValue(bCardData[0]);
        int bCardColor = GetCardColor(bCardData[0]);

        //设置结果
        //ZeroMemory(&AnalyseData, sizeof(AnalyseData));

        //扑克分析
        for (int i = 1; i<bCardCount; i++)
        {
            //获取扑克
            bCardValueTemp = GetCardLogicValue(bCardData[i]);
            if (bCardValueTemp == bLogicValue) bSameCount++;

            //保存结果
            if ((bCardValueTemp != bLogicValue) || (i == (bCardCount - 1)) || bCardData[i] == 0)
            {
                switch (bSameCount)
                {
                    case 1:		//一张
                        break;
                    case 2:		//两张
                    {
                        AnalyseData.bTwoFirst[AnalyseData.bTwoCount] = bFirstCardIndex;
                        AnalyseData.bTwoCount++;
                        break;
                    }
                    case 3:		//三张
                    {
                        AnalyseData.bThreeFirst[AnalyseData.bThreeCount] = bFirstCardIndex;
                        AnalyseData.bThreeCount++;
                        break;
                    }
                    case 4:		//四张
                    {
                        AnalyseData.bFourFirst[AnalyseData.bFourCount] = bFirstCardIndex;
                        AnalyseData.bFourCount++;
                        break;
                    }
                    case 5:		//5张
                    {
                        AnalyseData.bFiveFirst[AnalyseData.bFiveCount] = bFirstCardIndex;
                        AnalyseData.bFiveCount++;
                        break;
                    }
                    default:
                        //MyMsgBox(_T("AnalyseCard：错误扑克！: %d") , bSameCount);
                        break;
                }
            }

            //王牌自动转化同花
            if (bCardData[i] == 0)
            {
                bSameColorCount += bCardCount - i;
                if (bSameCount == 1)
                {
                    AnalyseData.bOneFirst[AnalyseData.bOneCount] = bFirstCardIndex;
                    AnalyseData.bOneCount++;
                }
                break;
            }

            //设置变量
            if (bCardValueTemp != bLogicValue)
            {
                if (bSameCount == 1)
                {
                    if (i != bCardCount - 1)
                    {
                        AnalyseData.bOneFirst[AnalyseData.bOneCount] = bFirstCardIndex;
                        AnalyseData.bOneCount++;
                    }
                    else
                    {
                        AnalyseData.bOneFirst[AnalyseData.bOneCount] = bFirstCardIndex;
                        AnalyseData.bOneCount++;
                        AnalyseData.bOneFirst[AnalyseData.bOneCount] = i;
                        AnalyseData.bOneCount++;
                    }
                }
                else
                {
                    if (i == bCardCount - 1)
                    {
                        AnalyseData.bOneFirst[AnalyseData.bOneCount] = i;
                        AnalyseData.bOneCount++;
                    }
                }
                bSameCount = 1;
                bLogicValue = bCardValueTemp;
                bFirstCardIndex = i;

            }
            if (GetCardColor(bCardData[i]) != bCardColor) bSameColorCount = 1;
            else									   ++bSameColorCount;
        }

        //是否同花
        AnalyseData.bSameColor = (5 == bSameColorCount) ? true : false;

        return;
    }


    /****************************************************
     *函数名：TransformCard
     *功能：  用于对已确定潜质牌型的牌进行转换,只能由AnalyseMaxTransform函数使用 JJ
     *参数：	 cbNkCardData		除去王的牌组	IN
     cbCardCount		牌数目(1-5)			IN
     bKCount			王数目(0-4)			IN
     bCardType			牌潜质类型(即转化方向)  IN
     tad				牌型信息				IN
     bTransCardData		转化后牌数组(升序排列)	OUT
     TransData			转化信息				INOUT
     *返回值：无(本函数不检查数据，数据检查由本函数唯一调用
     者AnalyseMaxTransform进行)
     zhaozw 下面需要改，因为最多可能4个王
     ****************************************************/
    void TransformCard( int cbNkCardData[], int bCardCount, int bKCount, int bCardType,  tagAnalyseData tad,
                                   int bTransCardData[], tagTransData TransData)
    {
//        //ASSERT((3 == bCardCount || 5 == bCardCount) && (1 == bKCount || 2 == bKCount || 3 == bKCount || 4 == bKCount || 5 == bKCount));

        //变量定义
        List<Integer> cardList = new ArrayList<>();			//记录转化后牌数组
        int bTempCardData[] = new int[5];

        for (int i = 0; i < bCardCount - bKCount; i++)
        {
            bTempCardData[i] = cbNkCardData[i];
        }
        //初始化
//        memcpy(bTempCardData, cbNkCardData, sizeof(int)*(bCardCount - bKCount));
        for (int i = 0; i < bCardCount - bKCount; i++)
        {
            cardList.add(bTempCardData[i]);
        }

        //转化开始
        switch (bCardType)
        {
            //顺子的转化算法是从非王最小牌开始,往上增直到非王最大牌发现有空缺先填空缺，没有空缺则根据是否到终点填充两头
            case CT_FIVE_STRAIGHT_FLUSH_FIRST_A:
            case CT_FIVE_STRAIGHT_FLUSH_BACK_A:
            case CT_FIVE_STRAIGHT_FLUSH_NO_A:
            case CT_FIVE_MIXED_FLUSH_FIRST_A:
            case CT_FIVE_MIXED_FLUSH_BACK_A:
            case CT_FIVE_MIXED_FLUSH_NO_A:
            {
                //数据校验
//                //ASSERT(5 == bCardCount);

                //升序排列			(仅顺子使用升序排列)
                SortCardList(bTempCardData, 5 - bKCount, enSortCardType.enAscend);

                //清空链表
                cardList.clear();

                //定义变量
                int bLogicHeadCard = 0;		//最小牌的逻辑值
                int bTempCount = 0;			//转化进行到的位置
                int bCardColor = GetCardColor(bTempCardData[0]);

                //填充首部
                if (bCardType == CT_FIVE_STRAIGHT_FLUSH_FIRST_A || bCardType == CT_FIVE_MIXED_FLUSH_FIRST_A)
                {
                    bLogicHeadCard = 1;
                    if (GetCardLogicValue(bTempCardData[5 - bKCount - 1]) != GetCardLogicValue(0x31))
                    {
                        if (bCardType == CT_FIVE_STRAIGHT_FLUSH_FIRST_A)
                        {
                            cardList.add(16 * bCardColor + 1);
                            TransData.transList.add(16 * bCardColor + 1);
                        }
                        else{
                            cardList.add(0x31);
                            TransData.transList.add(0x31);
                        }
                    }
                    else{
                        cardList.add(bTempCardData[5 - bKCount - 1]);
                    }
                    bTempCount = 0;
                }
                else
                {
                    bLogicHeadCard = GetCardLogicValue(bTempCardData[0]);
                    cardList.add(bTempCardData[0]);
                    bTempCount = 1;
                }

                //填充剩余
                for (int i = 1; i < 5; i++)
                {
                    if (GetCardLogicValue(bTempCardData[bTempCount]) != bLogicHeadCard + i)
                    {
                        int transCard = 0;
                        if (bCardType == CT_FIVE_STRAIGHT_FLUSH_FIRST_A || bCardType == CT_FIVE_STRAIGHT_FLUSH_NO_A)
                            transCard = (bCardColor << 4) + bLogicHeadCard + i;
                        else
                            transCard = 0x30 + bLogicHeadCard + i;
                        cardList.add(transCard);
                        TransData.transList.add(transCard);
                    }
                    else
                    {
                        cardList.add(bTempCardData[bTempCount]);
                        bTempCount++;
                    }
                    if (bTempCount == 5 - bKCount)
                        break;
                }
                //zhaozw TODO 这里根据m_cbFrontASmall 如果A前顺不是最小，判断如果最大值小于5的情况下组成A前顺
                //剩余王牌
                if (cardList.size() != 5)
                {
                    while (cardList.size() < 5)
                    {
                        int bLastCard = cardList.get(cardList.size()-1);
                        int bFirstCard = cardList.get(0);
                        int transCard = 0;
                        boolean bMaxEnd = (GetCardLogicValue(bLastCard) == 14);
                        int bExValue = GetCardLogicValue(bMaxEnd ? bFirstCard : bLastCard) + (bMaxEnd ? -1 : 1);
                        if (bExValue == 14)		bExValue = 1;

                        if (bCardType == CT_FIVE_STRAIGHT_FLUSH_FIRST_A || bCardType == CT_FIVE_STRAIGHT_FLUSH_NO_A)
                            transCard = (bCardColor << 4) + bExValue;
                        else
                            transCard = 0x30 + bExValue;

                        if (bMaxEnd)
                            cardList.add(0,transCard);
                        else
                            cardList.add(transCard);
                        TransData.transList.add(transCard);
                    }
                }

                break;
            }
            //炸弹的转化算法是直接找到3张的或者2张的，王变成同值的黑桃牌
            case CT_FIVE_FOUR_ONE:
            {
                //数据校验
//                //ASSERT(5 == bCardCount);

                //王牌转化
                if (bKCount == 1)
                {
                    int transCard = 0x30 + GetCardValue(bTempCardData[tad.bThreeFirst[0]]);
                    cardList.add(transCard);
                    TransData.transList.add(transCard);
                }
                else if (bKCount == 2)
                {
                    if (tad.bThreeCount == 1)
                    {
                        int transCard = 0x30 + GetCardValue(bTempCardData[tad.bThreeFirst[0]]);
                        cardList.add(transCard);
                        TransData.transList.add(transCard);

                        if (GetCardLogicValue(bTempCardData[tad.bThreeFirst[0]]) == 14)
                            transCard = 0x3D;
                        else
                            transCard = 0x31;
                        cardList.add(transCard);
                        TransData.transList.add(transCard);
                    }
                    else
                    {
                        int transCard = 0x30 + GetCardValue(bTempCardData[tad.bTwoFirst[0]]);
                        cardList.add(transCard);
                        cardList.add(transCard);
                        TransData.transList.add(transCard);
                        TransData.transList.add(transCard);
                    }
                }
                else if (bKCount == 3)
                {
                    if (tad.bOneCount == 2)
                    {
                        int transCard = 0x30 + GetCardValue(bTempCardData[tad.bOneFirst[0]]);
                        cardList.add(transCard);
                        cardList.add(transCard);
                        cardList.add(transCard);
                        TransData.transList.add(transCard);
                        TransData.transList.add(transCard);
                        TransData.transList.add(transCard);
                    }
                }

                break;
            }
            case CT_FIVE_SAME:
            {
                //数据校验
//                //ASSERT(5 == bCardCount);

                //王牌转化
                if (bKCount == 1)
                {
                    int transCard = 0x30 + GetCardValue(bTempCardData[tad.bFourFirst[0]]);
                    cardList.add(transCard);
                    TransData.transList.add(transCard);
                }
                else if (bKCount == 2)
                {
                    if (tad.bFourCount == 1)
                    {
                        int transCard = 0x30 + GetCardValue(bTempCardData[tad.bFourFirst[0]]);
                        cardList.add(transCard);
                        TransData.transList.add(transCard);

                        if (GetCardLogicValue(bTempCardData[tad.bFourFirst[0]]) == 14)
                            transCard = 0x3D;
                        else
                            transCard = 0x31;
                        cardList.add(transCard);
                        TransData.transList.add(transCard);
                    }
                    else
                    {
                        int transCard = 0x30 + GetCardValue(bTempCardData[tad.bThreeFirst[0]]);
                        cardList.add(transCard);
                        cardList.add(transCard);
                        TransData.transList.add(transCard);
                        TransData.transList.add(transCard);
                    }
                }
                else if (bKCount == 3)
                {
                    if (tad.bTwoCount == 1)
                    {
                        int transCard = 0x30 + GetCardValue(bTempCardData[tad.bTwoFirst[0]]);
                        cardList.add(transCard);
                        cardList.add(transCard);
                        cardList.add(transCard);
                        TransData.transList.add(transCard);
                        TransData.transList.add(transCard);
                        TransData.transList.add(transCard);
                    }
                    else
                    {
                    }
                }
                else if (bKCount == 4)
                {
                    if (tad.bOneCount == 1)
                    {
                        int transCard = 0x30 + GetCardValue(bTempCardData[tad.bOneFirst[0]]);
                        cardList.add(transCard);
                        cardList.add(transCard);
                        cardList.add(transCard);
                        cardList.add(transCard);
                        TransData.transList.add(transCard);
                        TransData.transList.add(transCard);
                        TransData.transList.add(transCard);
                        TransData.transList.add(transCard);
                    }
                    else
                    {
                    }
                }

                break;
            }
            //葫芦的转化算法是直接找到2对2张中大的，王变成同值的黑桃牌
            case CT_FIVE_THREE_DEOUBLE:
            {
                //数据校验
//                //ASSERT(5 == bCardCount&&bKCount == 1);

                //王牌转化
                int transCard = 0x30 + GetCardValue(bTempCardData[tad.bTwoFirst[0]]);
                cardList.add(transCard);
                TransData.transList.add(transCard);
                break;
            }
            //同花的转化算法是王变成同花
            case CT_FIVE_FLUSH:
            {
                //数据校验
//                //ASSERT(5 == bCardCount);

                int bCardColor = GetCardColor(bTempCardData[0]);

                //zhaozw
                /**/
                //王牌转化
                if (bKCount == 1)
                {

                    if (tad.bTwoCount==2)
                    {
                        int transCard = (bCardColor << 4) + 0x01;
                        cardList.add(transCard);
                        TransData.transList.add(transCard);
                    }
                    else if (tad.bTwoCount == 1)
                    {
                        int transCard = bTempCardData[tad.bOneFirst[0]];
                        cardList.add(transCard);
                        TransData.transList.add(transCard);
                    }
                    else{
                        int transCard = bTempCardData[tad.bOneFirst[0]];
                        cardList.add(transCard);
                        TransData.transList.add(transCard);
                    }
                }
                else if (bKCount == 2)
                {

                    int transCard = bTempCardData[tad.bOneFirst[0]];
                    cardList.add(transCard);
                    TransData.transList.add(transCard);

                    transCard = bTempCardData[tad.bOneFirst[1]];
                    cardList.add(transCard);
                    TransData.transList.add(transCard);
                }
						  /*
						  //王牌转化
						  while (cardList.size() < 5)
						  {
							  int transCard = (bCardColor << 4) + 0x01;
							  cardList.add(transCard);
							  TransData.transList.add(transCard);
						  }*/
                break;
            }
            //三条的转化算法是直接找到2张的或者单牌最大的，王变成同值的黑桃牌
            case CT_THREE:
            {
                //王牌转化
                if (tad.bTwoCount == 1)
                {
                    int transCard = 0x30 + GetCardValue(bTempCardData[tad.bTwoFirst[0]]);
                    cardList.add(transCard);
                    TransData.transList.add(transCard);
                }
                else
                {
                    while (cardList.size() < bCardCount)
                    {
                        int transCard = 0x30 + GetCardValue(bTempCardData[0]);
                        cardList.add(transCard);
                        TransData.transList.add(transCard);
                    }
                }
                break;
            }
            //一对的转化算法是直接找到单牌最大的，王变成同值的黑桃牌
            case CT_ONE_DOUBLE:
            {
                //数据校验
//                //ASSERT(1 == bKCount);

                //王牌转化
                int transCard = 0x30 + GetCardValue(bTempCardData[0]);
                cardList.add(transCard);
                TransData.transList.add(transCard);

                break;
            }
            default:
            {
                //MyMsgBox(_T("CGameLogic::TransFormCard [%d]"), bCardType);
                break;
            }
        }
        //填充信息
//        //ASSERT(cardList.size() == 5 || cardList.size() == 3);
        for (int i = 0; i < bCardCount; i++)
        {
//            bTransCardData[i] = cardList.GetAt(cardList.FindIndex(i));//zhaozw
            bTransCardData[i] = cardList.get(i);
        }

        return;
    }
    /****************************************************
     *函数名：AnalyseMaxTransform
     *功能：  根据牌型和王牌数目对牌进行最大转换 JJ
     *参数：	 cbCardData			牌数组			IN
     cbCardCount		牌数目			IN
     bTransCardData		转化后牌数组	OUT
     TransData			转化信息		OUT
     *返回值：0					不转化
     other				转化后的牌型
     ****************************************************/
    int AnalyseMaxTransform( int cbCardData[],  int cbCardCount, int bTransCardData[], tagTransData TransData)
    {
//        //ASSERT(cbCardCount == 3 || cbCardCount == 5);

        //变量声明
        int bTempCardData[] = new int[5];		//保存清空王后的数组
        int bKcount = 0;					//王数目

        for (int i = 0; i < cbCardCount; i++)
        {
            bTransCardData[i] = cbCardData[i];
            bTempCardData[i] = cbCardData[i];
        }
        //初始化
//        memcpy(bTransCardData, cbCardData, sizeof(int)*cbCardCount);
//        memcpy(bTempCardData, cbCardData, sizeof(int)*cbCardCount);

        //将王牌置0并统计
        for (int i = 0; i < cbCardCount; i++)
        {
            if (bTempCardData[i]>0x40)
            {
                TransData.bHaveKing += ((bTempCardData[i] == 0x41) ? 1 : 2);
                bTempCardData[i] = 0;
                bKcount++;
            }
        }
        TransData.bKingCount = bKcount;

        //无王返回
        if (bKcount == 0)
            return 0;

        //有王则分析牌数组
        SortCardList(bTempCardData, cbCardCount, enSortCardType.enDescend);
        tagAnalyseData	tad = new tagAnalyseData();
        AnalyseCard(bTempCardData, cbCardCount, tad);

        //炸弹直接返回
	/*if (tad.bFourCount == 1)
	return 0;*/

        //潜质判断	(从大到小依次计算)


        //5 zhaozw 下面需要改，因为最多可能4个王
        if (5 == cbCardCount && (1 == tad.bFiveCount || (1 == bKcount && 1 == tad.bFourCount) || (2 == bKcount && (1 == tad.bThreeCount)) || (3 == bKcount && (1 == tad.bTwoCount)) || (4 == bKcount && (1 == tad.bOneCount))))
        {
            TransformCard(bTempCardData, cbCardCount, bKcount, CT_FIVE_SAME, tad, bTransCardData, TransData);
            return CT_FIVE_SAME;
        }
        //同花顺 (5张牌 且 同花 且 全单牌)
        if (5 == cbCardCount && tad.bSameColor && 0 == (tad.bTwoCount + tad.bThreeCount + tad.bFourCount))
        {
            //A当1用，有A 且 第二大数字小于等于5, 最小顺子A2345
            if (5 >= GetCardLogicValue(bTempCardData[0]) || (GetCardLogicValue(bTempCardData[0]) == GetCardLogicValue(0x01) && 5 >= GetCardLogicValue(bTempCardData[1])))
            {
                TransformCard(bTempCardData, cbCardCount, bKcount, CT_FIVE_STRAIGHT_FLUSH_FIRST_A, tad, bTransCardData, TransData);
                return CT_FIVE_STRAIGHT_FLUSH_FIRST_A;
            }

            //最大牌减去最小牌小于等于4
            if (4 >= GetCardLogicValue(bTempCardData[0]) - GetCardLogicValue(bTempCardData[5 - bKcount - 1]))
            {
                TransformCard(bTempCardData, cbCardCount, bKcount, CT_FIVE_STRAIGHT_FLUSH_NO_A, tad, bTransCardData, TransData);
                return CT_FIVE_STRAIGHT_FLUSH_NO_A;
            }
        }

        //炸弹	(5张牌 且 单王3张数目等于一或者双王2张数目或者3张数目等于一)
        if (5 == cbCardCount && ((1 == bKcount && 1 == tad.bThreeCount) || (2 == bKcount && (1 == tad.bThreeCount || 1 == tad.bTwoCount) || bKcount == 3)))
        {
            TransformCard(bTempCardData, cbCardCount, bKcount, CT_FIVE_FOUR_ONE, tad, bTransCardData, TransData);
            return CT_FIVE_FOUR_ONE;
        }

        //葫芦  (5张牌 且 单王2张数目等于2）
        if (5 == cbCardCount && 1 == bKcount && 2 == tad.bTwoCount)
        {
            TransformCard(bTempCardData, cbCardCount, bKcount, CT_FIVE_THREE_DEOUBLE, tad, bTransCardData, TransData);
            return CT_FIVE_THREE_DEOUBLE;
        }

        //同花  (5张牌 且 全部同花）
        //if (5 == cbCardCount && tad.bSameColor)
        if (5 == cbCardCount && ((1 == bKcount && tad.bSameColor) || (2 == bKcount && tad.bSameColor)))
        {
            TransformCard(bTempCardData, cbCardCount, bKcount, CT_FIVE_FLUSH, tad, bTransCardData, TransData);
            return CT_FIVE_FLUSH;
        }

        //顺子	(5张牌 且 非同花 且 全单牌)
        if (5 == cbCardCount && !tad.bSameColor && 0 == (tad.bTwoCount + tad.bThreeCount + tad.bFourCount))
        {
            //A当1用，有A 且 第二大数字小于等于5, 最小顺子A2345
            if (5 >= GetCardLogicValue(bTempCardData[0]) || (GetCardLogicValue(bTempCardData[0]) == GetCardLogicValue(0x01) && 5 >= GetCardLogicValue(bTempCardData[1])))
            {
                TransformCard(bTempCardData, cbCardCount, bKcount, CT_FIVE_MIXED_FLUSH_FIRST_A, tad, bTransCardData, TransData);
                return CT_FIVE_MIXED_FLUSH_FIRST_A;
            }

            //最大牌减去最小牌小于等于4
            if (4 >= GetCardLogicValue(bTempCardData[0]) - GetCardLogicValue(bTempCardData[5 - bKcount - 1]))
            {
                TransformCard(bTempCardData, cbCardCount, bKcount, CT_FIVE_MIXED_FLUSH_NO_A, tad, bTransCardData, TransData);
                return CT_FIVE_MIXED_FLUSH_NO_A;
            }
        }

        //三条  (3或5张牌 且 单王2张数目等于1或双王全单牌)
        if ((1 == bKcount && 1 == tad.bTwoCount) || (2 == bKcount && 0 == (tad.bTwoCount + tad.bThreeCount + tad.bFourCount)))
        {
            TransformCard(bTempCardData, cbCardCount, bKcount, CT_THREE, tad, bTransCardData, TransData);
            return CT_THREE;
        }

        //两对  (不存在)

        //一对  (3或5张牌 且单王全单牌)
        if (1 == bKcount && 0 == (tad.bTwoCount + tad.bThreeCount + tad.bFourCount))
        {
            TransformCard(bTempCardData, cbCardCount, bKcount, CT_ONE_DOUBLE, tad, bTransCardData, TransData);
            return CT_ONE_DOUBLE;
        }

        //这里正常来说是不可能到的，到了只能说有Bug。。。
        //MyMsgBox(_T("%d %d [%s %s %s %s %s]"), cbCardCount, bKcount, bTempCardData[0]
        //, bTempCardData[1], bTempCardData[2], bTempCardData[3], bTempCardData[4]);
        return CT_SINGLE;
    }

    //比较扑克
    COMRESULT CompareCard(int bInFirstList[], int bInNextList[], int bFirstCount, int bNextCount, boolean bComperWithOther)
    {
        //定义变量
        int bFirstList[] = new int[13];
        int bNextList[] = new int[13];
        tagAnalyseData FirstAnalyseData = new tagAnalyseData(), NextAnalyseData = new tagAnalyseData();
        //ZeroMemory(&FirstAnalyseData, sizeof(FirstAnalyseData));
        //ZeroMemory(&NextAnalyseData, sizeof(NextAnalyseData));

        //检查转化
        tagTransData ttdFst = new tagTransData();
        tagTransData ttdNxt = new tagTransData();
        AnalyseMaxTransform(bInFirstList, bFirstCount, bFirstList, ttdFst);
        AnalyseMaxTransform(bInNextList, bNextCount, bNextList, ttdNxt);

        //排序牌组
        SortCardList(bFirstList, bFirstCount, enSortCardType.enDescend);
        SortCardList(bNextList, bNextCount, enSortCardType.enDescend);

        //分析牌组
        AnalyseCard(bFirstList, bFirstCount, FirstAnalyseData);
        AnalyseCard(bNextList, bNextCount, NextAnalyseData);

        //数据验证
//        //ASSERT(bFirstCount == (FirstAnalyseData.bOneCount + FirstAnalyseData.bTwoCount * 2 + FirstAnalyseData.bThreeCount * 3 + FirstAnalyseData.bFourCount * 4 + FirstAnalyseData.bFiveCount * 5));
//        //ASSERT(bNextCount = (NextAnalyseData.bOneCount + NextAnalyseData.bTwoCount * 2 + NextAnalyseData.bThreeCount * 3 + NextAnalyseData.bFourCount * 4 + NextAnalyseData.bFiveCount * 5));
        if (bFirstCount != (FirstAnalyseData.bOneCount + FirstAnalyseData.bTwoCount * 2 + FirstAnalyseData.bThreeCount * 3 + FirstAnalyseData.bFourCount * 4 + FirstAnalyseData.bFiveCount * 5))
        {
            return COMRESULT.enCRError;
        }
        if (bNextCount != (NextAnalyseData.bOneCount + NextAnalyseData.bTwoCount * 2 + NextAnalyseData.bThreeCount * 3 + NextAnalyseData.bFourCount * 4 + NextAnalyseData.bFiveCount * 5))
        {
            return COMRESULT.enCRError;
        }

//        //ASSERT((bFirstCount == bNextCount) || (bFirstCount != bNextCount && (3 == bFirstCount && 5 == bNextCount || 5 == bFirstCount && 3 == bNextCount)));
        if (!((bFirstCount == bNextCount) || (bFirstCount != bNextCount && (3 == bFirstCount && 5 == bNextCount || 5 == bFirstCount && 3 == bNextCount)))) return COMRESULT.enCRError;

//        //ASSERT(3 == bNextCount || 5 == bNextCount);
//        //ASSERT(3 == bFirstCount || 5 == bFirstCount);

        //获取类型
        int cbMaxCard = 0;
        int bNextType = GetCardType(bNextList, bNextCount, cbMaxCard);
        int bFirstType = GetCardType(bFirstList, bFirstCount, cbMaxCard);

//        //ASSERT(CT_INVALID != bNextType && CT_INVALID != bFirstType);
        if (CT_INVALID == bFirstType || CT_INVALID == bNextType) return COMRESULT.enCRError;

        //同段比较
        if (true == bComperWithOther)
        {
            //开始对比
            if (bNextType == bFirstType)
            {
                switch (bFirstType)
                {
                    case CT_SINGLE:				//单牌类型
                    {
                        //数据验证
                        ////ASSERT(bNextList[0]!=bFirstList[0]);
                        //if(bNextList[0]==bFirstList[0]) return enCRError;

                        for (int i = 0; i<bFirstCount; ++i)
                        {
                            if (GetCardLogicValue(bNextList[i]) > GetCardLogicValue(bFirstList[i]))
                                return COMRESULT.enCRGreater;
                            else if (GetCardLogicValue(bNextList[i]) < GetCardLogicValue(bFirstList[i]))
                                return COMRESULT.enCRLess;
                        }
                        for (int i = 0; i<bFirstCount; ++i)
                        {
                            if ((bNextList[i]) >(bFirstList[i]))
                                return COMRESULT.enCRGreater;
                            else if ((bNextList[i]) < (bFirstList[i]))
                                return COMRESULT.enCRLess;
                        }
                        return COMRESULT.enCREqual;
                    }
                    case CT_ONE_DOUBLE:			//对带一张
                    {
                        if (GetCardLogicValue(bNextList[NextAnalyseData.bTwoFirst[0]]) == GetCardLogicValue(bFirstList[FirstAnalyseData.bTwoFirst[0]]))
                        {

                            for (int i = 0; i<NextAnalyseData.bOneCount; ++i)
                            {
                                if (GetCardLogicValue(bNextList[NextAnalyseData.bOneFirst[i]]) > GetCardLogicValue(bFirstList[FirstAnalyseData.bOneFirst[i]]))
                                    return COMRESULT.enCRGreater;
                                else if (GetCardLogicValue(bNextList[NextAnalyseData.bOneFirst[i]]) < GetCardLogicValue(bFirstList[FirstAnalyseData.bOneFirst[i]]))
                                    return COMRESULT.enCRLess;
                            }
                            if (GetCardLogicValue(bNextList[NextAnalyseData.bOneFirst[0]]) > GetCardLogicValue(bFirstList[FirstAnalyseData.bOneFirst[0]]))
                                return COMRESULT.enCRGreater;
                            else if (GetCardLogicValue(bNextList[NextAnalyseData.bOneFirst[0]]) < GetCardLogicValue(bFirstList[FirstAnalyseData.bOneFirst[0]]))
                                return COMRESULT.enCRLess;
                            else{

                                if ((bNextList[NextAnalyseData.bOneFirst[0]]) > (bFirstList[FirstAnalyseData.bOneFirst[0]]))
                                    return COMRESULT.enCRGreater;
                                else if ((bNextList[NextAnalyseData.bOneFirst[0]]) < (bFirstList[FirstAnalyseData.bOneFirst[0]]))
                                    return COMRESULT.enCRLess;
                                else{
                                    if ((bNextList[NextAnalyseData.bTwoFirst[0]]) > (bFirstList[FirstAnalyseData.bTwoFirst[0]]))
                                        return COMRESULT.enCRGreater;
                                    else if ((bNextList[NextAnalyseData.bTwoFirst[0]]) < (bFirstList[FirstAnalyseData.bTwoFirst[0]]))
                                        return COMRESULT.enCRLess;
                                    else{
                                        if ((bNextList[NextAnalyseData.bTwoFirst[1]]) > (bFirstList[FirstAnalyseData.bTwoFirst[1]]))
                                            return COMRESULT.enCRGreater;
                                        else if ((bNextList[NextAnalyseData.bTwoFirst[1]]) < (bFirstList[FirstAnalyseData.bTwoFirst[1]]))
                                            return COMRESULT.enCRLess;
                                        else{
                                            return COMRESULT.enCREqual;
                                        }
//                                        return COMRESULT.enCREqual;
                                    }
//                                    return COMRESULT.enCREqual;
                                }
                            }
                        }
                        else
                        {
                            if (GetCardLogicValue(bNextList[NextAnalyseData.bTwoFirst[0]]) > GetCardLogicValue(bFirstList[FirstAnalyseData.bTwoFirst[0]]))
                                return COMRESULT.enCRGreater;
                            else
                                return COMRESULT.enCRLess;
                        }
                    }
                    case CT_TWO_DOUBLE:	//两对牌型
                    {
                        //数据验证
                        ////ASSERT(bNextList[NextAnalyseData.bTwoFirst[0]]!=bFirstList[FirstAnalyseData.bTwoFirst[0]]);
                        //if(bNextList[NextAnalyseData.bTwoFirst[0]]==bFirstList[FirstAnalyseData.bTwoFirst[0]]) return enCRError;

                        if (GetCardLogicValue(bNextList[NextAnalyseData.bTwoFirst[0]]) == GetCardLogicValue(bFirstList[FirstAnalyseData.bTwoFirst[0]]))
                        {
                            if (GetCardLogicValue(bNextList[NextAnalyseData.bTwoFirst[1]]) == GetCardLogicValue(bFirstList[FirstAnalyseData.bTwoFirst[1]]))
                            {
                                if (GetCardLogicValue(bNextList[NextAnalyseData.bOneFirst[0]]) > GetCardLogicValue(bFirstList[FirstAnalyseData.bOneFirst[0]]))
                                    return COMRESULT.enCRGreater;
                                else if (GetCardLogicValue(bNextList[NextAnalyseData.bOneFirst[0]]) < GetCardLogicValue(bFirstList[FirstAnalyseData.bOneFirst[0]]))
                                    return COMRESULT.enCRLess;
                                else{

                                    if ((bNextList[NextAnalyseData.bOneFirst[0]]) > (bFirstList[FirstAnalyseData.bOneFirst[0]]))
                                        return COMRESULT.enCRGreater;
                                    else if ((bNextList[NextAnalyseData.bOneFirst[0]]) < (bFirstList[FirstAnalyseData.bOneFirst[0]]))
                                        return COMRESULT.enCRLess;
                                    else{
                                        return COMRESULT.enCREqual;
                                    }
                                }
                            }
                            else
                            {
                                if (GetCardLogicValue(bNextList[NextAnalyseData.bTwoFirst[1]]) > GetCardLogicValue(bFirstList[FirstAnalyseData.bTwoFirst[1]]))
                                    return COMRESULT.enCRGreater;
                                else
                                    return COMRESULT.enCRLess;
                            }
                        }
                        else
                        {
                            if (GetCardLogicValue(bNextList[NextAnalyseData.bTwoFirst[0]]) > GetCardLogicValue(bFirstList[FirstAnalyseData.bTwoFirst[0]]))
                                return COMRESULT.enCRGreater;
                            else
                                return COMRESULT.enCRLess;
                        }
                    }
                    case CT_THREE:						//三张牌型
                    {
                        if (GetCardLogicValue(bNextList[NextAnalyseData.bThreeFirst[0]]) > GetCardLogicValue(bFirstList[FirstAnalyseData.bThreeFirst[0]]))
                            return COMRESULT.enCRGreater;
                        else if (GetCardLogicValue(bNextList[NextAnalyseData.bThreeFirst[0]]) < GetCardLogicValue(bFirstList[FirstAnalyseData.bThreeFirst[0]]))
                            return COMRESULT.enCRLess;
                        else{
                            if (GetCardLogicValue(bNextList[NextAnalyseData.bOneFirst[0]]) > GetCardLogicValue(bFirstList[FirstAnalyseData.bOneFirst[0]]))
                                return COMRESULT.enCRGreater;
                            else if (GetCardLogicValue(bNextList[NextAnalyseData.bOneFirst[0]]) < GetCardLogicValue(bFirstList[FirstAnalyseData.bOneFirst[0]]))
                                return COMRESULT.enCRLess;
                            else{
                                if (bNextCount == 5)
                                {
                                    if ((bNextList[NextAnalyseData.bOneFirst[0]]) > (bFirstList[FirstAnalyseData.bOneFirst[0]]))
                                        return COMRESULT.enCRGreater;
                                    else if ((bNextList[NextAnalyseData.bOneFirst[0]]) < (bFirstList[FirstAnalyseData.bOneFirst[0]]))
                                        return COMRESULT.enCRLess;
                                    else{
                                        if (GetCardLogicValue(bNextList[NextAnalyseData.bOneFirst[1]]) > GetCardLogicValue(bFirstList[FirstAnalyseData.bOneFirst[1]]))
                                            return COMRESULT.enCRGreater;
                                        else if (GetCardLogicValue(bNextList[NextAnalyseData.bOneFirst[1]]) < GetCardLogicValue(bFirstList[FirstAnalyseData.bOneFirst[1]]))
                                            return COMRESULT.enCRLess;
                                        else{

                                            if ((bNextList[NextAnalyseData.bOneFirst[1]]) > (bFirstList[FirstAnalyseData.bOneFirst[1]]))
                                                return COMRESULT.enCRGreater;
                                            else if ((bNextList[NextAnalyseData.bOneFirst[1]]) < (bFirstList[FirstAnalyseData.bOneFirst[1]]))
                                                return COMRESULT.enCRLess;
                                            else{
                                                return COMRESULT.enCREqual;
                                            }
                                        }
                                    }
                                }
                                else{
                                    return COMRESULT.enCREqual;
                                }
                            }
                        }
                    }
                    case CT_FIVE_THREE_DEOUBLE:			//三条一对
                    {
                        if (GetCardLogicValue(bNextList[NextAnalyseData.bThreeFirst[0]]) == GetCardLogicValue(bFirstList[FirstAnalyseData.bThreeFirst[0]]))
                        {
                            if (GetCardLogicValue(bNextList[NextAnalyseData.bTwoFirst[0]]) > GetCardLogicValue(bFirstList[FirstAnalyseData.bTwoFirst[0]]))
                                return COMRESULT.enCRGreater;
                            else if (GetCardLogicValue(bNextList[NextAnalyseData.bTwoFirst[0]]) < GetCardLogicValue(bFirstList[FirstAnalyseData.bTwoFirst[0]]))
                                return COMRESULT.enCRLess;
                            else
                                return COMRESULT.enCREqual;
                        }
                        else
                        {
                            if (GetCardLogicValue(bNextList[NextAnalyseData.bThreeFirst[0]]) > GetCardLogicValue(bFirstList[FirstAnalyseData.bThreeFirst[0]]))
                                return COMRESULT.enCRGreater;
                            else
                                return COMRESULT.enCRLess;
                        }
                    }
                    case CT_FIVE_MIXED_FLUSH_FIRST_A:	//A在前顺子
                    case CT_FIVE_MIXED_FLUSH_BACK_A:	//A在后顺子
                    {
                        //比较最大的一张牌
                        //return enCREqual;

                        //比较花色
                        for (int i = 0; i < 5; i++)
                        {
                            if (GetCardColor(bNextList[i]) > GetCardColor(bFirstList[i]))
                                return COMRESULT.enCRGreater;
                            else if (GetCardColor(bNextList[i]) < GetCardColor(bFirstList[i]))
                                return COMRESULT.enCRLess;
                        }
                        return COMRESULT.enCREqual;
                    }
                    case CT_FIVE_MIXED_FLUSH_NO_A:		//没A杂顺
                    {
                        //比较数值
                        for (int i = 0; i<5; ++i)
                        {
                            if (GetCardLogicValue(bNextList[i]) > GetCardLogicValue(bFirstList[i]))
                                return COMRESULT.enCRGreater;
                            else if (GetCardLogicValue(bNextList[i]) < GetCardLogicValue(bFirstList[i]))
                                return COMRESULT.enCRLess;
                        }

                        //比较花色
                        for (int i = 0; i < 5; i++)
                        {
                            if (GetCardColor(bNextList[i]) > GetCardColor(bFirstList[i]))
                                return COMRESULT.enCRGreater;
                            else if (GetCardColor(bNextList[i]) < GetCardColor(bFirstList[i]))
                                return COMRESULT.enCRLess;
                        }
                        return COMRESULT.enCREqual;
                    }
                    case CT_FIVE_FOUR_ONE:				//四带一张
                    {
                        if (GetCardLogicValue(bNextList[NextAnalyseData.bFourFirst[0]]) > GetCardLogicValue(bFirstList[FirstAnalyseData.bFourFirst[0]]))
                            return COMRESULT.enCRGreater;
                        else if (GetCardLogicValue(bNextList[NextAnalyseData.bFourFirst[0]]) < GetCardLogicValue(bFirstList[FirstAnalyseData.bFourFirst[0]]))
                            return COMRESULT.enCRLess;
                        else{
                            if (GetCardLogicValue(bNextList[NextAnalyseData.bOneFirst[0]]) > GetCardLogicValue(bFirstList[FirstAnalyseData.bOneFirst[0]]))
                                return COMRESULT.enCRGreater;
                            else if (GetCardLogicValue(bNextList[NextAnalyseData.bOneFirst[0]]) < GetCardLogicValue(bFirstList[FirstAnalyseData.bOneFirst[0]]))
                                return COMRESULT.enCRLess;
                            else{
                                if ((bNextList[NextAnalyseData.bOneFirst[0]]) > (bFirstList[FirstAnalyseData.bOneFirst[0]]))
                                    return COMRESULT.enCRGreater;
                                else if ((bNextList[NextAnalyseData.bOneFirst[0]]) < (bFirstList[FirstAnalyseData.bOneFirst[0]]))
                                    return COMRESULT.enCRLess;
                                else{
                                }
                            }
                        }
                        return COMRESULT.enCREqual;
                    }
                    case CT_FIVE_SAME:		//同花顺牌
                    case CT_FIVE_FLUSH:					//同花五牌
                    case CT_FIVE_STRAIGHT_FLUSH_FIRST_A://A在前同花顺
                    case CT_FIVE_STRAIGHT_FLUSH_BACK_A://A在后同花顺
                    case CT_FIVE_FLUSH_DOUBLE:
                    case CT_FIVE_FLUSH_TWO_DOUBLE:
                    {
                        //zhaozw 对子花
                        if ((bFirstType == CT_FIVE_FLUSH && (FirstAnalyseData.bTwoCount>0 || NextAnalyseData.bTwoCount>0)) || bFirstType == CT_FIVE_FLUSH_DOUBLE || bFirstType == CT_FIVE_FLUSH_TWO_DOUBLE)
                        {
                            if (NextAnalyseData.bTwoCount > FirstAnalyseData.bTwoCount)
                            {
                                return COMRESULT.enCRGreater;
                            }
                            else if (NextAnalyseData.bTwoCount < FirstAnalyseData.bTwoCount)
                            {
                                return COMRESULT.enCRLess;
                            }
                            else if (GetCardLogicValue(bNextList[NextAnalyseData.bTwoFirst[0]]) > GetCardLogicValue(bFirstList[FirstAnalyseData.bTwoFirst[0]]))
                            {
                                return COMRESULT.enCRGreater;
                            }
                            else if (GetCardLogicValue(bNextList[NextAnalyseData.bTwoFirst[0]]) < GetCardLogicValue(bFirstList[FirstAnalyseData.bTwoFirst[0]]))
                            {
                                return COMRESULT.enCRLess;
                            }
                            else if (GetCardLogicValue(bNextList[NextAnalyseData.bTwoFirst[0]]) == GetCardLogicValue(bFirstList[FirstAnalyseData.bTwoFirst[0]]))
                            {
                                if (GetCardLogicValue(bNextList[NextAnalyseData.bTwoFirst[1]]) > GetCardLogicValue(bFirstList[FirstAnalyseData.bTwoFirst[1]]))
                                    return COMRESULT.enCRGreater;
                                else if (GetCardLogicValue(bNextList[NextAnalyseData.bTwoFirst[1]]) < GetCardLogicValue(bFirstList[FirstAnalyseData.bTwoFirst[1]]))
                                    return COMRESULT.enCRLess;
                            }
                        }
                        if (bFirstType == CT_FIVE_FLUSH && false)
                        {

                            if (NextAnalyseData.bTwoCount > FirstAnalyseData.bTwoCount)
                            {
                                return COMRESULT.enCRGreater;
                            }
                            else if (NextAnalyseData.bTwoCount < FirstAnalyseData.bTwoCount)
                            {
                                return COMRESULT.enCRLess;
                            }
                            else if (NextAnalyseData.bTwoCount>0){

                                if (GetCardLogicValue(bNextList[NextAnalyseData.bTwoFirst[0]]) > GetCardLogicValue(bFirstList[FirstAnalyseData.bTwoFirst[0]]))
                                {
                                    return COMRESULT.enCRGreater;
                                }
                                else if (GetCardLogicValue(bNextList[NextAnalyseData.bTwoFirst[0]]) < GetCardLogicValue(bFirstList[FirstAnalyseData.bTwoFirst[0]]))
                                {
                                    return COMRESULT.enCRLess;
                                }
                                else if (GetCardLogicValue(bNextList[NextAnalyseData.bTwoFirst[0]]) == GetCardLogicValue(bFirstList[FirstAnalyseData.bTwoFirst[0]]))
                                {
                                    if (GetCardLogicValue(bNextList[NextAnalyseData.bTwoFirst[1]]) > GetCardLogicValue(bFirstList[FirstAnalyseData.bTwoFirst[1]]))
                                        return COMRESULT.enCRGreater;
                                    else if (GetCardLogicValue(bNextList[NextAnalyseData.bTwoFirst[1]]) < GetCardLogicValue(bFirstList[FirstAnalyseData.bTwoFirst[1]]))
                                        return COMRESULT.enCRLess;
                                }
                            }
                        }

                        if (m_cbTongHuaMode == 0)
                        {
                            //比较数值
                            for (int i = 0; i<5; ++i)
                            {
                                if (GetCardLogicValue(bNextList[i]) > GetCardLogicValue(bFirstList[i]))
                                    return COMRESULT.enCRGreater;
                                else if (GetCardLogicValue(bNextList[i]) < GetCardLogicValue(bFirstList[i]))
                                    return COMRESULT.enCRLess;
                            }

                            //比较花色
                            for (int i = 0; i < 5; i++)
                            {
                                if (GetCardColor(bNextList[i]) > GetCardColor(bFirstList[i]))
                                    return COMRESULT.enCRGreater;
                                else if (GetCardColor(bNextList[i]) < GetCardColor(bFirstList[i]))
                                    return COMRESULT.enCRLess;
                            }
                        }
                        else
                        {
                            //比较花色
                            for (int i = 0; i < 5; i++)
                            {
                                if (GetCardColor(bNextList[i]) > GetCardColor(bFirstList[i]))
                                    return COMRESULT.enCRGreater;
                                else if (GetCardColor(bNextList[i]) < GetCardColor(bFirstList[i]))
                                    return COMRESULT.enCRLess;
                            }

                            //比较数值
                            for (int i = 0; i<5; ++i)
                            {
                                if (GetCardLogicValue(bNextList[i]) > GetCardLogicValue(bFirstList[i]))
                                    return COMRESULT.enCRGreater;
                                else if (GetCardLogicValue(bNextList[i]) < GetCardLogicValue(bFirstList[i]))
                                    return COMRESULT.enCRLess;
                            }

                        }



                        //比较花色
                        for (int i = 0; i < 5; i++)
                        {
                            if (GetCardColor(bNextList[i]) > GetCardColor(bFirstList[i]))
                                return COMRESULT.enCRGreater;
                            else if (GetCardColor(bNextList[i]) < GetCardColor(bFirstList[i]))
                                return COMRESULT.enCRLess;
                        }
                        return COMRESULT.enCREqual;
                    }
                    case CT_FIVE_STRAIGHT_FLUSH_NO_A:		//同花顺牌
                    {
                        //比较数值
                        for (int i = 0; i<5; ++i)
                        {
                            if (GetCardLogicValue(bNextList[i]) > GetCardLogicValue(bFirstList[i]))
                                return COMRESULT.enCRGreater;
                            else if (GetCardLogicValue(bNextList[i]) < GetCardLogicValue(bFirstList[i]))
                                return COMRESULT.enCRLess;
                        }

                        //比较花色
                        for (int i = 0; i < 5; i++)
                        {
                            if (GetCardColor(bNextList[i]) > GetCardColor(bFirstList[i]))
                                return COMRESULT.enCRGreater;
                            else if (GetCardColor(bNextList[i]) < GetCardColor(bFirstList[i]))
                                return COMRESULT.enCRLess;
                        }
                        return COMRESULT.enCREqual;
                    }
                    default:
                        return COMRESULT.enCRError;
                }
            }
            else
            {
                if (m_cbFrontASmall == 1)
                {
                    if (bNextType == CT_FIVE_MIXED_FLUSH_NO_A &&bFirstType == CT_FIVE_MIXED_FLUSH_FIRST_A){
                        return COMRESULT.enCRGreater;
                    }
                    if (bFirstType == CT_FIVE_MIXED_FLUSH_NO_A &&bNextType == CT_FIVE_MIXED_FLUSH_FIRST_A){
                        return COMRESULT.enCRLess;
                    }
                    if (bNextType == CT_FIVE_STRAIGHT_FLUSH_NO_A &&bFirstType == CT_FIVE_STRAIGHT_FLUSH_FIRST_A){
                        return COMRESULT.enCRGreater;
                    }
                    if (bFirstType == CT_FIVE_STRAIGHT_FLUSH_NO_A &&bNextType == CT_FIVE_STRAIGHT_FLUSH_FIRST_A){
                        return COMRESULT.enCRLess;
                    }
                }
                if (bNextType > bFirstType)
                    return COMRESULT.enCRGreater;
                else
                    return COMRESULT.enCRLess;
            }
        }
        else
        {
            //ASSERT(bFirstType == CT_SINGLE || bFirstType == CT_ONE_DOUBLE || bFirstType == CT_THREE);
            if (bFirstType != CT_SINGLE && bFirstType != CT_ONE_DOUBLE && bFirstType != CT_THREE)
                return COMRESULT.enCRError;
            //开始对比
            if (bNextType == bFirstType)
            {
                switch (bFirstType)
                {
                    case CT_SINGLE:				//单牌类型
                    {
                        //数据验证
                        ////ASSERT(bNextList[0]!=bFirstList[0]);
                        //if(bNextList[0]==bFirstList[0]) return enCRError;

                        for (int i = 0; i<bFirstCount; ++i)
                        {
                            if (GetCardLogicValue(bNextList[i]) > GetCardLogicValue(bFirstList[i]))
                                return COMRESULT.enCRGreater;
                            else if (GetCardLogicValue(bNextList[i]) < GetCardLogicValue(bFirstList[i]))
                                return COMRESULT.enCRLess;
                        }

                        if (bNextCount > bFirstCount)
                            return COMRESULT.enCRGreater;
                        else
                            return COMRESULT.enCRLess;
                    }
                    case CT_ONE_DOUBLE:			//对带一张
                    {
                        if (GetCardLogicValue(bNextList[NextAnalyseData.bTwoFirst[0]]) == GetCardLogicValue(bFirstList[FirstAnalyseData.bTwoFirst[0]]))
                        {
                            if (GetCardLogicValue(bNextList[NextAnalyseData.bOneFirst[0]]) > GetCardLogicValue(bFirstList[FirstAnalyseData.bOneFirst[0]]))
                                return COMRESULT.enCRGreater;
                            else if (GetCardLogicValue(bNextList[NextAnalyseData.bOneFirst[0]]) < GetCardLogicValue(bFirstList[FirstAnalyseData.bOneFirst[0]]))
                                return COMRESULT.enCRLess;
                            else
                            {
                                if (bNextCount > bFirstCount)
                                    return COMRESULT.enCRGreater;
                                else
                                    return COMRESULT.enCRLess;
                            }
                        }
                        else
                        {
                            if (GetCardLogicValue(bNextList[NextAnalyseData.bTwoFirst[0]]) > GetCardLogicValue(bFirstList[FirstAnalyseData.bTwoFirst[0]]))
                                return COMRESULT.enCRGreater;
                            else
                                return COMRESULT.enCRLess;
                        }
                    }
                    case CT_THREE:				//三张牌型
                    {
                        if (GetCardLogicValue(bNextList[NextAnalyseData.bThreeFirst[0]]) > GetCardLogicValue(bFirstList[FirstAnalyseData.bThreeFirst[0]]))
                            return COMRESULT.enCRGreater;
                        else if (GetCardLogicValue(bNextList[NextAnalyseData.bThreeFirst[0]]) < GetCardLogicValue(bFirstList[FirstAnalyseData.bThreeFirst[0]]))
                            return COMRESULT.enCRLess;
                        else
                        {
                            if (bNextCount > bFirstCount)
                                return COMRESULT.enCRGreater;
                            else
                                return COMRESULT.enCRLess;
                        }
                    }
                    default:
                        return COMRESULT.enCRError;
                }
            }
            else
            {
                if (bNextType > bFirstType)
                    return COMRESULT.enCRGreater;
                else
                    return COMRESULT.enCRLess;
            }
        }

//        return COMRESULT.enCRError;
    }

    //分析扑克
    void AnalysebCardData( int cbCardData[], int cbCardCount, tagAnalyseResult AnalyseResult)
    {
        //设置结果
        //ZeroMemory(&AnalyseResult, sizeof(AnalyseResult));

        //扑克分析
        for (int i = 0; i<cbCardCount; i++)
        {
            //变量定义
            int cbSameCount = 1;
            int cbLogicValue = GetCardLogicValue(cbCardData[i]);

            //搜索同牌
            for (int j = i + 1; j<cbCardCount; j++)
            {
                //获取扑克
                if (GetCardLogicValue(cbCardData[j]) != cbLogicValue) break;

                //设置变量
                cbSameCount++;
            }

            //设置结果
            int cbIndex = AnalyseResult.cbBlockCount[cbSameCount - 1]++;
            for (int j = 0; j < cbSameCount; j++)
                AnalyseResult.cbCardData[cbSameCount - 1][cbIndex*cbSameCount + j] = cbCardData[i + j];

            //设置索引
            i += (cbSameCount - 1);
        }

        return;
    }

    //分析分布
    void AnalysebDistributing( int cbCardData[], int cbCardCount, tagDistributing Distributing)
    {
        //设置变量
        //ZeroMemory(&Distributing, sizeof(Distributing));

        //设置变量
        for (int i = 0; i<cbCardCount; i++)
        {
            if (cbCardData[i] == 0) continue;

            //获取属性
            int cbCardColor = GetCardColor(cbCardData[i]);
            int cbCardValue = GetCardValue(cbCardData[i]);

            //分布信息
            Distributing.cbCardCount++;
            Distributing.cbDistributing[cbCardValue - 1][cbIndexCount]++;
            Distributing.cbDistributing[cbCardValue - 1][cbCardColor]++;
        }

        return;
    }
    //逻辑数值
    int GetCardLogicValue(int bCardData)
    {
        //扑克属性
        int bCardValue = GetCardValue(bCardData);

        if (bCardData == 0x41)
        {
            return 15;
        }
        if (bCardData >= 0x42)
        {
            return 16;
        }

        //转换数值
        return (bCardValue == 1) ? (bCardValue + 13) : bCardValue;
    }
    int GetCardValue(int bCardData) { return bCardData&LOGIC_MASK_VALUE; }
    int GetCardColor(int bCardData) { return (bCardData&LOGIC_MASK_COLOR)>>4; }


    int SearchLineCardType(int cbHandCardData[], int cbHandCardCount, int cbLineCount, tagSearchCardResult pSearchCardResult)
    {
        //设置结果
        if (pSearchCardResult!=null){//zhaozw TODO
//            for (int i = 0; i < pSearchCardResult; i++) {
//
//            }
        }
//            ZeroMemory(pSearchCardResult, sizeof(tagSearchCardResult));

        //定义变量
        int cbResultCount = 0;
        int cbBlockCount = 1;

        //超过A
        if (cbLineCount > 14) return cbResultCount;

        //长度判断
        if (cbHandCardCount < cbLineCount) return cbResultCount;

        //构造扑克
        int cbCardData[] = new int[HAND_CARD_COUNT];
        int cbCardCount = cbHandCardCount;
        for (int i = 0; i < cbHandCardCount; i++) {
            cbCardData[i] = cbHandCardData[i];
        }
//        CopyMemory(cbCardData, cbHandCardData, sizeof(int)*cbHandCardCount);

        //排列扑克
        SortCardList(cbCardData, cbCardCount, enSortCardType.enDescend);

        //分析扑克
        tagDistributing Distributing = new tagDistributing();
//        ZeroMemory(&Distributing, sizeof(Distributing));
        AnalysebDistributing(cbCardData, cbCardCount, Distributing);

        //搜索顺子
        int cbTmpLinkCount = 0;
        int cbValueIndex = 0;
        for (cbValueIndex = 0; cbValueIndex<13; cbValueIndex++)
        {
            //继续判断
            if (Distributing.cbDistributing[cbValueIndex][cbIndexCount]< cbBlockCount)
            {
                if (cbTmpLinkCount < cbLineCount)
                {
                    cbTmpLinkCount = 0;
                    continue;
                }
                else cbValueIndex--;
            }
            else
            {
                cbTmpLinkCount++;

                //寻找最长连
                if (cbLineCount == 0) continue;
            }

            if (cbTmpLinkCount >= cbLineCount)
            {
                if (pSearchCardResult == null) return 1;

//                ASSERT(cbResultCount < CountArray(pSearchCardResult.cbCardCount));

                //复制扑克
                int cbCount = 0;
                for (int cbIndex = cbValueIndex + 1 - cbTmpLinkCount; cbIndex <= cbValueIndex; cbIndex++)
                {
                    int cbTmpCount = 0;
                    for (int cbColorIndex = 0; cbColorIndex<4; cbColorIndex++)
                    {
                        for (int cbColorCount = 0; cbColorCount < Distributing.cbDistributing[cbIndex][3 - cbColorIndex]; cbColorCount++)
                        {
                            pSearchCardResult.cbResultCard[cbResultCount][cbCount++] = MakeCardData(cbIndex, 3 - cbColorIndex);

                            if (++cbTmpCount == cbBlockCount) break;
                        }
                        if (cbTmpCount == cbBlockCount) break;
                    }
                }

                //设置变量
                pSearchCardResult.cbCardCount[cbResultCount] = cbCount;
                cbResultCount++;

                cbTmpLinkCount--;
            }
        }

        //特殊顺子
        if (cbTmpLinkCount >= cbLineCount - 1 && cbValueIndex == 13)
        {
            if (Distributing.cbDistributing[0][cbIndexCount] >= cbBlockCount || cbTmpLinkCount >= cbLineCount)
            {
                if (pSearchCardResult == null) return 1;

//                ASSERT(cbResultCount < CountArray(pSearchCardResult.cbCardCount));

                //复制扑克
                int cbCount = 0;
                int cbTmpCount = 0;
                for (int cbIndex = cbValueIndex - cbTmpLinkCount; cbIndex < 13; cbIndex++)
                {
                    cbTmpCount = 0;
                    for (int cbColorIndex = 0; cbColorIndex<4; cbColorIndex++)
                    {
                        for (int cbColorCount = 0; cbColorCount < Distributing.cbDistributing[cbIndex][3 - cbColorIndex]; cbColorCount++)
                        {
                            pSearchCardResult.cbResultCard[cbResultCount][cbCount++] = MakeCardData(cbIndex, 3 - cbColorIndex);

                            if (++cbTmpCount == cbBlockCount) break;
                        }
                        if (cbTmpCount == cbBlockCount) break;
                    }
                }

                //复制A
                if (Distributing.cbDistributing[0][cbIndexCount] >= cbBlockCount)
                {
                    cbTmpCount = 0;
                    for (int cbColorIndex = 0; cbColorIndex<4; cbColorIndex++)
                    {
                        for (int cbColorCount = 0; cbColorCount < Distributing.cbDistributing[0][3 - cbColorIndex]; cbColorCount++)
                        {
                            pSearchCardResult.cbResultCard[cbResultCount][cbCount++] = MakeCardData(0, 3 - cbColorIndex);

                            if (++cbTmpCount == cbBlockCount) break;
                        }
                        if (cbTmpCount == cbBlockCount) break;
                    }
                }

                //设置变量
                pSearchCardResult.cbCardCount[cbResultCount] = cbCount;
                cbResultCount++;
            }
        }

        if (pSearchCardResult!=null)
            pSearchCardResult.cbSearchCount = cbResultCount;
        return cbResultCount;
    }

    //构造扑克
    int MakeCardData(int cbValueIndex, int cbColorIndex)
    {
        return (cbColorIndex << 4) | (cbValueIndex + 1);
    }

    //删除扑克
    boolean RemoveCard(int bRemoveCard[], int bRemoveCount, int bCardData[], int cbTemp[], int bCardCount)
    {
        //检验数据
//        ASSERT(bRemoveCount <= bCardCount);

        //定义变量
        int bDeleteCount = 0, bTempCardData[] = new int[13];
        if (bCardCount > bTempCardData.length) return false;
        for (int i = 0; i < bCardCount; i++) {
            bTempCardData[i] = bCardData[i];
        }
//        CopyMemory(bTempCardData, bCardData, bCardCount*sizeof(bCardData[0]));

        //置零扑克
        for (int i = 0; i<bRemoveCount; i++)
        {
            for (int j = 0; j < bCardCount; j++)
            {
                if (bRemoveCard[i] == bTempCardData[j])
                {
                    bDeleteCount++;
                    bTempCardData[j] = 0;
                    break;
                }
            }
        }
        if (bDeleteCount != bRemoveCount) return false;

        //清理扑克
        int bCardPos = 0;
        for (int i = 0; i < bCardCount; i++)
        {
            if (bTempCardData[i] != 0) cbTemp[bCardPos++] = bTempCardData[i];
        }

        return true;
    }
}
